剛剛開始使用 AWS SAM。想使用 Lambda 和 DynamoDB 創建一個 CRUD 微服務我的 template.yaml:
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: >-
A simple backend (read/write to DynamoDB) with a RESTful API endpoint using Amazon API Gateway.
Resources:
microservicehttpendpoint:
Type: 'AWS::Serverless::Function'
Properties:
Handler: index.handler
Runtime: nodejs12.x
CodeUri: .
Description: >-
A simple backend (read/write to DynamoDB) with a RESTful API endpoint using Amazon API Gateway.
MemorySize: 512
Timeout: 10
Policies:
- DynamoDBCrudPolicy:
TableName: MyTable
Events:
Api1:
Type: Api
Properties:
Path: /MyResource
Method: ANY
MyTable:
Type: AWS::Serverless::SimpleTable
Properties:
PrimaryKey: name
TableName: dynocrud-table
我希望創建三個資源:a) Lambda,b) Api 網關端點,3) DynamoDB 表 Lambda 和 API 網關端點正在按預期創建,但沒有 DynamoDB 表,也沒有錯誤。這是 cli 輸出:
sam deploy
Uploading to dyno-crud/5c01af22215fe32fe7f18fa00be 5706 / 5706 (100.00%)
Deploying with following values
===============================
Stack name : dyno-crud
Region : us-east-1
Confirm changeset : True
Disable rollback : False
Deployment s3 bucket : aws-sam-cli-managed-default-samclisourcebucket-141rt5mvjki0m
Capabilities : ["CAPABILITY_IAM"]
Parameter overrides : {"TableNameParameter": "dynocrud-table"}
Signing Profiles : {}
Initiating deployment
=====================
Uploading to dyno-crud/d085f2bf53ae0ab235eabed4814.template 897 / 897 (100.00%)
Waiting for changeset to be created..
CloudFormation stack changeset
-----------------------------------------------------------------------------------------------------------------
Operation LogicalResourceId ResourceType Replacement
-----------------------------------------------------------------------------------------------------------------
Add ServerlessRestApiDeploymen AWS::ApiGateway::Deploymen N/A
t1fee5cc247 t
Add ServerlessRestApiProdStage AWS::ApiGateway::Stage N/A
Add ServerlessRestApi AWS::ApiGateway::RestApi N/A
Add microservicehttpendpointAp AWS::Lambda::Permission N/A
i1PermissionProd
Add microservicehttpendpointRo AWS::IAM::Role N/A
le
Add microservicehttpendpoint AWS::Lambda::Function N/A
-----------------------------------------------------------------------------------------------------------------
Changeset created successfully. arn:aws:cloudformation:us-east-1:458815622243:changeSet/samcli-deploy1639025652/bcbadc92-6106-4cb4-b551-54f3b9774936
Previewing CloudFormation changeset before deployment
======================================================
Deploy this changeset? [y/N]: y
2021-12-08 22:54:43 - Waiting for stack create/update to complete
CloudFormation events from stack operations
-----------------------------------------------------------------------------------------------------------------
ResourceStatus ResourceType LogicalResourceId ResourceStatusReason
-----------------------------------------------------------------------------------------------------------------
CREATE_IN_PROGRESS AWS::IAM::Role microservicehttpendpointRo -
le
CREATE_IN_PROGRESS AWS::IAM::Role microservicehttpendpointRo Resource creation
le Initiated
CREATE_COMPLETE AWS::IAM::Role microservicehttpendpointRo -
le
CREATE_IN_PROGRESS AWS::Lambda::Function microservicehttpendpoint -
CREATE_IN_PROGRESS AWS::Lambda::Function microservicehttpendpoint Resource creation
Initiated
CREATE_COMPLETE AWS::Lambda::Function microservicehttpendpoint -
CREATE_IN_PROGRESS AWS::ApiGateway::RestApi ServerlessRestApi -
CREATE_COMPLETE AWS::ApiGateway::RestApi ServerlessRestApi -
CREATE_IN_PROGRESS AWS::ApiGateway::RestApi ServerlessRestApi Resource creation
Initiated
CREATE_IN_PROGRESS AWS::Lambda::Permission microservicehttpendpointAp -
i1PermissionProd
CREATE_IN_PROGRESS AWS::Lambda::Permission microservicehttpendpointAp Resource creation
i1PermissionProd Initiated
CREATE_IN_PROGRESS AWS::ApiGateway::Deploymen ServerlessRestApiDeploymen -
t t1fee5cc247
CREATE_IN_PROGRESS AWS::ApiGateway::Deploymen ServerlessRestApiDeploymen Resource creation
t t1fee5cc247 Initiated
CREATE_COMPLETE AWS::ApiGateway::Deploymen ServerlessRestApiDeploymen -
t t1fee5cc247
CREATE_IN_PROGRESS AWS::ApiGateway::Stage ServerlessRestApiProdStage -
CREATE_IN_PROGRESS AWS::ApiGateway::Stage ServerlessRestApiProdStage Resource creation
Initiated
CREATE_COMPLETE AWS::ApiGateway::Stage ServerlessRestApiProdStage -
CREATE_COMPLETE AWS::Lambda::Permission microservicehttpendpointAp -
i1PermissionProd
CREATE_COMPLETE AWS::CloudFormation::Stack dyno-crud -
-----------------------------------------------------------------------------------------------------------------
Successfully created/updated stack - dyno-crud in us-east-1
為了與其他資源一起創建 DynamoDB 表,我應該更改什么?
uj5u.com熱心網友回復:
請確保您的 yaml 檔案已正確縮進。本Type:應在資源的名稱下方縮進,如
MyTable:
Type: AWS::Serverless::SimpleTable <-- indented here
Properties:
PrimaryKey: name
TableName: dynocrud-table
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/377882.html
標籤:亚马逊网络服务 亚马逊动态数据库 aws-无服务器 aws-sam
上一篇:無法在AWSs3上托管靜態網站
