I'm using sam deploy to deploy 2 dynamoDB tables. But I keep getting errors relating to the fact it cannot resolve [Environment] such as:
Error: Failed to create changeset for the stack: <STACKNAME>, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state: For expression "Status" we matched expected path: "FAILED" Status: FAILED. Reason: Template format error: Unresolved resource dependencies [Environment] in the Resources block of the template
The sam template is:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: <Description>
Resources:
Database:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Sub "${Environment}-Membership_Database"
AttributeDefinitions:
- AttributeName: "id"
AttributeType: "S"
- AttributeName: "membershipNumber"
AttributeType: "N"
KeySchema:
- AttributeName: "id"
KeyType: "HASH"
- AttributeName: "membershipNumber"
KeyType: "RANGE"
BillingMode: "PAY_PER_REQUEST"
MemberHistoryTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Sub "${Environment}-Membership_History"
AttributeDefinitions:
- AttributeName: "id"
AttributeType: "S"
- AttributeName: "time"
AttributeType: "S"
KeySchema:
- AttributeName: "id"
KeyType: "HASH"
- AttributeName: "time"
KeyType: "RANGE"
BillingMode: "PAY_PER_REQUEST"
TimeToLiveSpecification:
AttributeName: "ttl"
Enabled: true
Outputs:
MembershipDatabaseTableName:
Description: "Table name of the membership database"
Value: !Ref Database
Export:
Name: !Sub "${AWS::StackId}-MembershipDatabaseTableName"
And by samconfig.toml looks like this: (I want to export several environment variables, but am concerned that this file is the issue).
version = 0.1
[staging.deploy.parameters]
stack_name = "Stack-Staging"
s3_prefix = "StackStaging"
region = "eu-west-2"
confirm_changeset = false
resolve_s3 = true
capabilities = ["CAPABILITY_IAM","CAPABILITY_AUTO_EXPAND"]
image_repositories = []
parameter_overrides=[
"Environment=staging",
"AdultsStripePaymentLink=https://buy.stripe.com/...",
"JuniorsStripePaymentLink=https://buy.stripe.com/...",
]
To run the deployment I'm running:
sam build
sam deploy --config-env staging
What am I doing wrong? Thank you in advance!