Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AWS Lambda + PlanetScale = 超絶スケールWebアプリ

AWS Lambda + PlanetScale = 超絶スケールWebアプリ

ServerlessでもRDBを利用して数百インスタンスが瞬時に起動するようなWebアプリをたった数ドルで作れる世界になりました
このスライドではその大枠を説明します

Hirokatsu Endo

July 18, 2023
Tweet

More Decks by Hirokatsu Endo

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ ‣ ԕ౻ େհ / @ruzia ‣ גࣜձࣾ SonicGarden ‣

    ϓϩάϥϚʔ / ࣥߦ໾һ ‣ Πϯϑϥͱػցֶशܥ͕޷͖ ‣ ϩʔυόΠΫ࠷ۙ৐Εͯͳ͍ ‣ FF16ʹͲͬ΀Γਁ͔Γத
  2. # Install the Runtime Interface Client RUN gem install --no-document

    aws_lambda_ric ENTRYPOINT ["/usr/local/bundle/bin/aws_lambda_ric"] CMD ["config/environment.Lamby.cmd"]
  3. functions: job: image: <<: *rails_image environment: ${self:custom.environment} memorySize: 1024 timeout:

    890 events: - schedule: name: HourlyJob-${self:service}-${self:provider.stage} rate: cron(0 * * * ? *) input: lamby: runner: './bin/rails task:hourly_job'
  4. #!/usr/bin/env bash set -e APP_NAME="sample" STAGE=${1:-staging} CLUSTER="${APP_NAME}-${STAGE}" ... LATEST_TASK_DEFINITION_ARN=$( aws

    ecs list-task-definitions --family-prefix $CLUSTER-oneoff ... ) echo "== Run console on Fargate..." echo "== Starting $LATEST_TASK_DEFINITION_ARN" TASK_ARN=$( aws ecs run-task --cluster $CLUSTER --task-definition $LATEST_TASK_DEFINITION_ARN ... ) echo "== TaskArn: ${TASK_ARN}" aws ecs wait tasks-running --cluster $CLUSTER --tasks $TASK_ARN echo "== Waiting for managed agent launch..." while true; do AGENT_STATUS=$( aws ecs describe-tasks --cluster $CLUSTER --tasks $TASK_ARN ... ) if [[ "$AGENT_STATUS" != "RUNNING" ]]; then sleep 1 else # ΤʔδΣϯτͷىಈ͔Β͞Βʹ 2 ඵ͘Β͍଴ͨͳ͍ͱ ssm ͕ܨ͕Βͳ͍ sleep 2 break fi done aws ecs execute-command --cluster $CLUSTER --task $TASK_ARN --container ${CLUSTER}-oneoff ... echo "== Stopping $LATEST_TASK_DEFINITION_ARN" aws ecs stop-task --cluster $CLUSTER --task $TASK_ARN > /dev/null 2>&1 ࠷৽ͷλεΫఆٛARNΛऔಘ λεΫΛ࣮ߦ λεΫͷىಈ଴ͪ Managed Agentͷىಈ଴ͪ ECS ExecͰϩάΠϯ λεΫΛऴྃ