A standard pattern using DynamoDB is to separate data used by each environment by prefixing the table names with any environment-specific string.
I assumed that this would be easy to do using ElasticBeanstalk and the CloudFormation configurations in .ebextensions
. However - for my platform (Java 8 running on 64bit Amazon Linux) at least - this seems not to be the case.
My naive implementation was to add an environment property (DB_PREFIX
) for each environment and then adapt my table creation config in .ebextensions
as follows:
Resources:
UserTable:
Type: AWS::DynamoDB::Table
Properties:
TableName:
Fn::Join:
- '_'
- - ${env:DB_PREFIX}
- 'User'
KeySchema:
HashKeyElement: {AttributeName: id, AttributeType: S}
ProvisionedThroughput: {ReadCapacityUnits: 1, WriteCapacityUnits: 1}
This doesn't work, possibly because, for my platform at least, environment properties are not made available as OS environment variables (see https://stackoverflow.com/a/36567121/96553 ).
I have also thought about conditionally setting an AWS environment property based on the environment name (not a great solution as it doesn't scale well) it might be acceptable.
Does anyone have a pattern that they're already using for this kind of problem?