从SAM模板yaml文件中在本地创建DynamoDB表。

huangapple go评论89阅读模式
英文:

Create DynamoDB tables locally from SAM Template yaml file

问题

你可以使用相同的 template.yaml 文件以 AWS::Serverless-2016-10-31 定义,通过 SAM/Cloud Formation 在本地创建 DynamoDB 表格吗?

DynamoDB 在本地运行时,可以使用以下命令启动:docker run -p 8000:8000 amazon/dynamodb-local,但是目前没有任何表格。

英文:

How can I create tables a Dynamo DB locally using the same template.yaml file with AWS::Serverless-2016-10-31 definition for SAM/Cloud Formation that I intent to use for production?

DynamoDB is running locally using docker run -p 8000:8000 amazon/dynamodb-local but has no tables.

答案1

得分: 1

通过安装一个用于解析YAML的CLI解析器,例如yq,它类似于流行的jq,你可以运行类似这样的Linux命令来配置本地DynamoDB表。这需要你的DynamoDB在本地开发时运行在标准端口8000上:

aws dynamodb create-table --cli-input-yaml "`cat template.yaml | yq .Resources.[MY TABLE NAME].Properties`" --no-cli-pager --endpoint-url http://localhost:8000

使用以下命令验证创建:

aws dynamodb list-tables --endpoint-url http://localhost:8000
英文:

By installing a CLI parser for yaml, example yq that reassembles the popular jq, you can run a linux command like this to configure your local Dynamo DB tables. This expects your DynamoDB to run on the standard port 8000 for local development:

aws dynamodb create-table --cli-input-yaml "`cat template.yaml | yq .Resources.[MY TABLE NAME].Properties`" --no-cli-pager --endpoint-url http://localhost:8000

Verify the creation using

aws dynamodb list-tables --endpoint-url http://localhost:8000

huangapple
  • 本文由 发表于 2023年5月29日 17:35:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76356211.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定