×


Understanding serverless.yml file, properties with simple explanation, variables in serverless.yml – Serverless Framework and aws

Serverles.yml
Property
Description
service
Will have the properties which describe the service for which the YAML file is for, properties like name, arn…
app
Name of the app you create service for. App should be created in serverless and name can be found in serverless.com dashboard
org
Multiple organizations can be created in serverless and this property indicates the organization for which the service is created
package
Include/Exclude files or folders in the deployment package. Example,to exclude git folder,node_modules..
provider
This Will have the properties for the cloud service provider. Details like name(eg:AWS),runtime(eg:Node.js), region(eg:Ohio),and others like timeout,stage(dev,prod..) and memory
custom
Will have custom variables for services like base, params, role…
functions
Will have functions in the service. Functions can have name, handler, environment variables, description…
resources
We will have the resources used by the service, like DynamoDB tables, lambda…
output
Variable for refactoring. It can be used in other serverless.yml files. This Can be used along with different app/stage/region.Example: ${output:appname:stagename:regionname:my-service.var-key}

 

 

 

 

Variables in Serverless

Variables can be used in YAML file in different ways, the orange highlighted text indicates the various  ways

Variables are added using interpolation, variable values are referenced using ${}.

 

 

${self:provider.stage} – will interpolate stage value. Self means current YAML. self:  indicate self-reference

 

 

${opt:stage} –  option from command, for example.opt: indicate CLI options

serverless deploy --stage production --region eu-central-1

 

 

${sls:instanceId} – serverless core variables are referenced with sls: indicate serverless core variables.Instance ID is unique instance ID

 

 

${env:SOME_VAR}  – environment variables

 

 

${custom: ${file(../myCustomFile.yml)}  –   the entire file., external file

 

 

${name: ${s3:myBucket/myKey}-hello}variables from S3

 

 

${service: ${ssm:/path/to/service/id}SSM Parameter store

 

 

${supersecret: ${ssm:/aws/reference/secretsmanager/secret_ID_in_Secrets_Manager~true}}  AWS secrets manager

 

 

${custom: ${file(../config.js)}  – other js files

 

 

${param:SECRET_KEY_NAME} – params can be stored from serverless dashboard/CLI and can be accessed using param: Goto deployment profile and create parameters.

 

 

Read more here https://serverless.com/framework/docs/providers/aws/guide/variables/#pseudo-parameters-reference

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *