~2 min read|
Preamble: I am exploring different areas of AWS and am finding the jargon overwhelming. To help myself, I’ll be writing up summaries of some of the different services I come across, what they are, some core concepts, and links to resources for future reference.
All entries in the series are tagged with
aws in 30 secondsand can be found here.
SAM is a CLI for AWS. The acronym stands for Serverless Application Model and as the name suggests, it’s more than just writing lambdas locally. It’s a suite of tools for writing entire applications. From the “What is AWS SAM” documentation:
A serverless application is a combination of Lambda functions, event sources, and other resources that work together to perform tasks. Note that a serverless application is more than just a Lambda function—it can include additional resources such as APIs, databases, and event source mappings.
SAM uses CloudFormation which allows for consistent, automated deployments.
Bootstrap with a template
$ sam init
init will walk through an interactive set of prompts. Using these, it’s possible to get up and running using a set of blue prints for different types of apps (from the basic
helloWorld to more complex ones using S3, SNS, SQS, or even as a web backend. )
If you have Docker installed, you can run the entire application locally on port 3000 (default) with:
$ sam local start-api
Alternatively, you can test single invocations. The simplest way to do this is to call
invoke from within the application directory:
$ sam local invoke
You can specify what you want to invoke as well:
$ sam local invoke "HelloWorldFunction" -e events/event.json
This invocation will pick up the test event in the
event.json. Alternatively, you can pass in your own events at the time of invocation:
$ sam local generate-event apigateway aws-proxy --body "" --path "hello" --method GET > api-event.json $ diff events/api-event.json event/sevent.json
One of the big advantages to using
SAM is that the infrastructure is all spelled out in the
Because of that deployments are automated and you can verify your changes before pushing them up.
Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!