Local development
Invoking an AWS Lambda function locally
To invoke a function written for AWS Lambda locally, there are several options:
- Write a test in Vitest, and invoke your lambda programmatically;
- Use CDK with SAM to invoke your lambda from the command line;
- Use
@backpack/vite-plugin-lambda
to trigger your lambda from a local dev server. This is probably the best option when your Lambda integrates with API Gateway for REST APIs.
Cloud infrastructure & remote services
When you need to connect with cloud infrastructure (e.g. DynamoDB) or remote services, there are multiple approaches:
- You can connect your locally running app to an existing cloud environment using your personal credentials. Additionally, you could deploy a separate stack that uses a dedicated prefix/suffix to limit interference with other developers;
- Alternatively, you can run things locally:
- By emulating your infrastructure locally, e.g. using Docker Compose
- By mocking remote services, e.g. using WireMock.
Of course, you can also go for a combination. For example, connecting to remote services running in AWS, but using locally emulated infrastructure at the same time.
Resolve dynamic resources locally
Some resources (like DynamoDB table names) are resolved dynamically through environment variables in your CDK stack. To replicate this locally, you could use something like dotenv and the AWS CLI do a lookup for those resources:
dotenv
MY_TABLE_NAME="$(aws dynamodb list-tables --output=text | grep -o 'my-app-stack-MyTable.*')"