I am using the serverless framework to create a DynamoDB table and then I want to access it from a Lambda function.
In the serverless.yml file I have the definitions below for the environment variable and CF resources.
What I was expecting was a table with the name accounts-api-dev-accounts, but what the cloudformation stack is creating for me is accounts-api-dev-accounts-SOME_RANDOM_LETTERS_AND_NUMBERS_SUFFIX.
In my lambda function the environment variable DYNAMODB_ACCOUNTS_TABLE_NAME is exposed to the function without the SOME_RANDOM_LETTERS_AND_NUMBERS_SUFFIX part. Is the CF stack supposed to add a random suffix? How do I actually retrieve the right table name?
service:
name: accounts-api
provider:
...
stage: ${opt:stage, 'dev'}
environment:
DYNAMODB_ACCOUNTS_TABLE_NAME: '${self:service}-${self:provider.stage}-accounts'
And the following CF resource:
Resources:
AccountsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${env:DYNAMODB_ACCOUNTS_TABLE_NAME}
AttributeDefinitions:
- AttributeName: customerNumber
AttributeType: S
- AttributeName: accountNumber
AttributeType: S
KeySchema:
- AttributeName: customerNumber
KeyType: HASH
- AttributeName: accountNumber
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
${self:provider.environment.DYNAMODB_ACCOUNTS_TABLE_NAME}instead of${env:DYNAMODB_ACCOUNTS_TABLE_NAME}