Last active
July 14, 2020 09:04
-
-
Save crisecheverria/15ea7aa275df344f1d1f647eb0af91d1 to your computer and use it in GitHub Desktop.
example-serverless.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service: random-name | |
provider: | |
name: aws | |
runtime: nodejs12.x | |
stage: dev | |
environment: | |
usersTableName: ${self:custom.myEnvironment.usersTableName.${self:custom.myStage}} # This I used in my code as process.env.usersTablename | |
projectsTableName: ${self:custom.myEnvironment.projectsTableName.${self:custom.myStage}} | |
plugins: | |
- serverless-s3-sync | |
- serverless-offline | |
- serverless-dynamodb-local | |
- serverless-plugin-scripts | |
- serverless-webpack | |
package: | |
individually: true | |
# Here I create multiple environments for dev & prod. After deploy to AWS it works fine having users-dev and users-prod | |
custom: | |
myStage: ${opt:stage, self:provider.stage} | |
myEnvironment: | |
usersTableName: | |
dev: users-dev | |
prod: users-prod | |
projectsTableName: | |
dev: projects-dev | |
prod: projects-prod | |
functions: | |
getUser: | |
handler: functions/endpoints/Users/getUser.handler | |
events: | |
- http: | |
path: get-user/{Id} | |
method: GET | |
cors: true | |
#private: true | |
resources: | |
Resources: | |
UsersDynamoDBTable: | |
Type: AWS::DynamoDB::Table | |
Properties: | |
TableName: ${self:custom.myEnvironment.usersTableName.${self:custom.myStage}} | |
ProjectsDynamoDBTable: | |
Type: AWS::DynamoDB::Table | |
Properties: | |
TableName: ${self:custom.myEnvironment.projectsTableName.${self:custom.myStage}} | |
# And for the test I run something like this "projectsTableName=projects-dev jest" | |
# with no luck saying "ResourceNotFoundException: Cannot do operations on a non-existent table" | |
# For some reason "usersTableName=users jest" it works! | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment