I’m trying to setup env variable using SSM for database credentials. I want to use 3 database credentials
- local (in my machine)
- dev (on cloud)
- prod (on cloud)
I already setup this following
but the problem is, when I run “sls invoke local -f func_name --path input.json -s local” it works, it is using my local credentials of databse but also trying to retrieve dev and prod credentials with SSM.
When I turned my WIFI off , it gives error and function never runs.
this is my serverless.yml file
provider:
name: aws
runtime: python3.6
stage: ${opt:stage,‘dev’}
Environment Variables
environment:
MYSQL_HOST: ${self:custom.mysqlHost.${self:provider.stage}}
MYSQL_USER: ${self:custom.mysqlUser.${self:provider.stage}}
MYSQL_PASSWORD: ${self:custom.mysqlPassword.${self:provider.stage}}
MYSQL_DATABASE: ${self:custom.mysqlDatabase.${self:provider.stage}}
MYSQL_PORT: ${self:custom.mysqlPort.${self:provider.stage}}
plugins:
- serverless-python-requirements
- serverless-domain-manager
- serverless-stage-manager
custom:
customDomain:
basePath: ‘user’
stage: ${self:provider.stage}
createRoute53Record: true
pythonRequirements:
fileName: requirements.txt
dockerizePip: true
stages:
- dev
- staging
- prod
mysqlHost:
local: localhost
dev: ${ssm:/myapp/database/dev/mysql-host~true} #get from ssm
#staging: ${ssm:/myapp/staging/mysql-host} #get from ssm
prod: ${ssm:/myapp/database/prod/mysql-host~true} #get from ssm
mysqlUser:
local: root
dev: ${ssm:/myapp/database/dev/mysql-username~true} #get from ssm
# staging: myapp_stag
prod: ${ssm:/myapp/database/prod/mysql-username~true} #get from ssm
mysqlPassword:
local: ‘’ # No Password
dev: ${ssm:/myapp/database/dev/mysql-password~true} #get from ssm
# staging: ${ssm:/myapp/staging/mysql-password~true} #get from ssm (secure)
prod: ${ssm:/myapp/database/prod/mysql-password~true} #get from ssm
mysqlDatabase:
local: dbname
dev: ${ssm:/myapp/database/dev/mysql-dbname~true} #get from ssm
# staging: myapp_staging
prod: ${ssm:/myapp/database/prod/mysql-dbname~true} #get from ssm
mysqlPort:
local: ‘3306’
dev: ‘3306’
staging: ‘3306’
prod: ‘3306’