Skip to content

localstackを使ったAWSサービスの実装サンプル群

Notifications You must be signed in to change notification settings

shinkawk/aws_localsample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aws_localsample

まず初めに

pip install localstack
  • このリポジトリをローカル環境にコピー
git clone https://github.com/shinkawk/aws_localsample.git
  • コピーしたリポジトリの中でLocalStackのImageを作成&起動
docker-compose up -d

Local S3 サンプル

上記のDocker-compose up -dが正常に起動したことを確認すること

  • AWS S3のローカルバケットを作成
aws --endpoint-url=http://localhost:4572 s3 mb s3://demo-bucket
  • 作成したバケットに読み込み権限を付与
aws --endpoint-url=http://localhost:4572 s3api put-bucket-acl --bucket demo-bucket --acl public-read
python local_s3.py

Local DynamoDB

  • AWS DynamoDBのローカルテーブルを作成
aws dynamodb create-table
    --table-name Music
    --attribute-definitions
        AttributeName=Artist,AttributeType=S
        AttributeName=SongTitle,AttributeType=S
    --key-schema AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE
    --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1
    --endpoint-url http://localhost:4569
  • 作成したDynamoDBを確認
aws dynamodb list-tables --endpoint-url http://localhost:4569
  • local_dynamo.pyを起動
python local_dynamo.py

Local Lambda

コードは以下で作成可能(レポジトリではすでに作成済み)

sam init --runtime python3.7
  • local lambdaを起動
cd local_lambda\
sam local start-api
sam local invoke "HelloWorldFunction" -e events/event.json
  • local lambda用のevent jsonの作成方法
sam local generate-event apigateway aws-proxy --body "" --path "hello" --method GET > api-event.json

↑で作成されるファイルはEncodeがUTF16になるので必ずUTF8にしてから実行すること

About

localstackを使ったAWSサービスの実装サンプル群

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages