make_download
- Code for the application's Lambda function.events
- Invocation events that you can use to invoke the function.tests
- Unit tests for the application code.template.yaml
- A template that defines the application's AWS resources.Makefile
- Makefile for your convenience to install deps, build, invoke, and deploy your application.
Already know this sample? Run:
make hurry
- This command will install app deps, build, and deploy your Serverless application using SAM.
Build and deploy your application for the first time by running the following commands in your shell:
mpcontribs-serverless$ make build
mpcontribs-serverless$ make deploy.guided
The first command will build the source of your application within a Docker container. The second command will package and deploy your application to AWS. Guided deploy means SAM CLI will ask you about the name of your deployment/stack, AWS Region, and whether you want to save your choices, so that you can use make deploy
next time.
Whenever you change your application code, you'll have to run build command:
mpcontribs-serverless$ make build
The SAM CLI installs dependencies defined in make_download/requirements.txt
, creates a deployment package, and saves it in the .aws-sam/build
folder.
Test a single function by invoking it directly with a test event:
mpcontribs-serverless$ make invoke
An event is a JSON document that represents the input that the function receives from the event source. Test events are included in the
events
folder in this project.
To simplify troubleshooting, SAM CLI has a command called sam logs
. sam logs
lets you fetch logs generated by your deployed Lambda function from the command line. In addition to printing the logs on the terminal, this command has several nifty features to help you quickly find the bug.
mpcontribs-serverless$ sam logs -n MPContribsMakeDownloadFunction --stack-name <Name-of-your-deployed-stack> --tail
Tests are defined in the tests
folder in this project, and we use Pytest as the test runner for this sample project.
Make sure you install dev dependencies before you run tests with make dev
:
mpcontribs-serverless$ make dev
mpcontribs-serverless$ make test
mpcontribs-serverless$ aws cloudformation delete-stack --stack-name mpcontribs-serverless
We included a Makefile
for your convenience - You can find all commands you can use by running make
. Under the hood, we're using SAM CLI commands to run these common tasks:
make build
:sam build --use-container
make deploy.guided
:sam deploy --guided
make invoke
:sam local invoke MPContribsMakeDownloadFunction --event events/make_download.json
make run
:sam local start-api
Pipenv takes care of isolating dev dependencies and app dependencies. As SAM CLI requires a requirements.txt
file, you'd need to generate one if new app dependencies have been added:
mpcontribs-serverless$ pipenv lock -r > make_download/requirements.txt