AWS SAM 自習3日目「DynamoDBデプロイ」
AWS SAM からDynamoDBをデプロイします。
2日目に作成した template.yaml に下記を追加します。
Resources:
SamSampleFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
・・・
SamSampleTable:
Type: AWS::Serverless::SimpleTable
Properties:
PrimaryKey:
Name: id
Type: Number
TableName: samSimpleTable
Tags:
AppType: Serverless
sam build
ビルドします。
$ sam build
Building codeuri: sam-sample/ runtime: nodejs14.x metadata: {} functions: ['SamSampleFunction']
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrc
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Build Succeeded
Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml
Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Deploy: sam deploy --guided
sam deploy --guided
デプロイします。
$ sam deploy --guided
Configuring SAM deploy
======================
Looking for config file [samconfig.toml] : Found
Reading default arguments : Success
Setting default arguments for 'sam deploy'
=========================================
Stack Name [sam-app02]:
AWS Region [ap-northeast-1]:
#Shows you resources changes to be deployed and require a 'Y' to initiate deploy
Confirm changes before deploy [y/N]:
#SAM needs permission to be able to create roles to connect to the resources in your template
Allow SAM CLI IAM role creation [Y/n]:
Save arguments to configuration file [Y/n]:
SAM configuration file [samconfig.toml]:
SAM configuration environment [default]:
・・・
Waiting for changeset to be created..
CloudFormation stack changeset
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Operation LogicalResourceId ResourceType Replacement
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Add SamSampleTable AWS::DynamoDB::Table N/A
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Changeset created successfully. arn:aws:cloudformation:・・・
2022-02-13 22:03:26 - Waiting for stack create/update to complete
CloudFormation events from changeset
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ResourceStatus ResourceType LogicalResourceId ResourceStatusReason
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE_IN_PROGRESS AWS::DynamoDB::Table SamSampleTable -
CREATE_IN_PROGRESS AWS::DynamoDB::Table SamSampleTable Resource creation Initiated
CREATE_COMPLETE AWS::DynamoDB::Table SamSampleTable -
UPDATE_COMPLETE_CLEANUP_IN_PROGRESS AWS::CloudFormation::Stack sam-app02 -
UPDATE_COMPLETE AWS::CloudFormation::Stack sam-app02 -
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CloudFormation outputs from deployed stack
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Outputs
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key SamSampleFunctionIamRole
Description Implicit IAM Role created for Sam Sample function
Value arn:aws:iam::・・・
Key SamSampleFunction
Description Sam Sample Lambda Function ARN
Value arn:aws:lambda:・・・
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Successfully created/updated stack - sam-app02 in ap-northeast-1
DynamoDB コンソール
コンソールでテーブルの作成を確認します。