This workshop is intended to give a basic overview of AWS SAM and its functionalities.
- AWS CLI
- AWS SAM CLI
- Docker
AWS Serverless Application Model is a model which combines the development and architectural requirements of serverless applications. Developers can write application code and architecture-as-code into one and the same project, and deploy all-together to AWS.
AWS SAM has a CLI which can be leveraged to validate, build, test locally and deploy. There are also other AWS SAM CLI commands available. See the documentation for more info.
AWS SAM is also implemented on top of AWS CloudFormation. It forms an additional abstraction layer which is useful specifically when building serverless applications and architectures.
A template.yaml
made for AWS SAM has the Transform: AWS::Serverless-2016-10-31
at the top of the template file. During deployment, AWS SAM will transform and expand the SAM-syntax into AWS CloudFormation syntax before deploying the stack.
This validates your template.yaml file.
This will locally build your project.
This command will help you test your Lambda-functions locally after writing its code and configuring it in template.yaml
. You can provide an event file (JSON-format) which will serve as the "input".
sam local invoke HelloWorldFunction --event .\events\test.json --profile <aws-cli-profile>
Any logging executed within the function will be printed to the console, as well as the output of the Lambda-function.
This automatically packages and deploys your code and template to AWS. It creates an artifact which it uploads to an S3-bucket. This bucket can either be managed automatically by AWS SAM (auto-resolved), or it can be a bucket you have provided.
# Deploy template.yaml, resolve the S3 automatically and use the default config file (.\samconfig.toml)
sam deploy --resolve-s3 --profile <aws-cli-profile>
# Deploy template.yaml, resolve the S3 automatically and use a custom config file (.\config\tst.toml)
sam deploy --resolve-s3 --profile <aws-cli-profile> --config-file .\config\tst.toml
You can provide a config file when executing any SAM command. By default, AWS SAM will look for a file named samconfig.toml
in the root of the project. You can have multiple config files in a repository and use the CLI option to choose a specific one. This is useful when setting up different environments or when using pipelines.
Here are some common configuration options;
stack_name = "string"
for the name of the AWS CloudFormation stackresolve_s3 = boolean
to choose whether AWS SAM should automatically create and manage an S3-bucket for artifactsregion = "<aws-region-name>"
the region where the stack should be deployedconfirm_changeset = boolean
to choose whether AWS SAM should ask for confirmation before deploying a stack after showing the changesetparameter_overrides = "var1=val1 var2=val2"
parameters which will be passed to thetemplate.yaml
CloudFormation parameters when deploying