The AWS SAM CLI allows developers to build and test applications locally without the need to deploy resources to the AWS cloud. This allows for faster iterations during development.
The AWS SAM CLI has the ability to performing linting on your template to make sure it's valid. This is done through the use of cfn-lint capabilities integrated with the CLI.
Standard Python tooling can be used to test Lambda applications. You should use standard testing tooling to ensure your application is behaving as expected. You can run the following command to test each Lambda function:
make test
AWS SAM allows us to build and invoke our Lambda functions. Below are the steps for each.
make local-build
The following commands can be used to invoke the VanillaFunction
successfully locally.
# Valid event
make local-vanilla
# Invalid event - invalid email address
sam local invoke VanillaFunction -e events/invalid_user_invalid_email.json
# Invalid event - missing field
sam local invoke VanillaFunction -e events/invalid_user_missing_attribute.json
The following commands can be used to invoke the InstrumentedFunction
successfully locally.
# Valid event
make local-instrumented
# Invalid event - invalid email address
sam local invoke InstrumentedFunction -e events/invalid_user_invalid_email.json
# Invalid event - missing field
sam local invoke InstrumentedFunction -e events/invalid_user_missing_attribute.json
The following commands can be used to invoke the OtelFunction
successfully locally.
# Valid event
make local-otel
# Invalid event - invalid email address
sam local invoke OtelFunction -e events/invalid_user_invalid_email.json
# Invalid event - missing field
sam local invoke OtelFunction -e events/invalid_user_missing_attribute.json
Now that your function is building and invoking locally as expected, let's deploy our Lambda functions to the AWS cloud.