I am following a CloudFormation tutorial and this is my AWS CloudFormation template:
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: A starter AWS Lambda function.
Resources:
helloworldpython3:
Type: 'AWS::Serverless::Function'
Properties:
Handler: app.lambda_handler
Runtime: python3.6
CodeUri: src/
Description: A starter AWS Lambda function.
MemorySize: 128
Timeout: 3
Environment:
Variables:
TABLE_NAME: !Ref Table
REGION_NAME: !Ref AWS::Region
Events:
HelloWorldSAMAPI:
Type: Api
Properties:
Path: /hello
Method: GET
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref Table
Table:
Type: AWS::Serverless::SimpleTable
Properties:
PrimaryKey:
Name: greeting
Type: String
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
I can generate the final template with aws cloudformation package
. But when I try to deploy it with sam deploy
, I get this output from the shell:
error : Waiting for changeset to be created.. Error: Failed to create changeset for the stack: hello-world-sam, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state: For expression "Status" we matched expected path: "FAILED" Status: FAILED. Reason: Invalid template property or properties [Table]
Your YAML is not correctly formatted:
AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Description: A starter AWS Lambda function.
Resources:
helloworldpython3:
Type: "AWS::Serverless::Function"
Properties:
Handler: app.lambda_handler
Runtime: python3.6
CodeUri: src/
Description: A starter AWS Lambda function.
MemorySize: 128
Timeout: 3
Environment:
Variables:
TABLE_NAME: !Ref Table
REGION_NAME: !Ref AWS::Region
Events:
HelloWorldSAMAPI:
Type: Api
Properties:
Path: /hello
Method: GET
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref Table
Table:
Type: AWS::Serverless::SimpleTable
Properties:
PrimaryKey:
Name: greeting
Type: String
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
Table
should be under the Resources
. Use a linter like cfn-python-lint