Skip to main content

AWS Lambda Packaging Methods

1. Package Creation

First, let's create deployment packages for deploying to Lambda. Start by running npm install.

[ec2-user ~] cd serverless-backend-application-stack-nodejs/
[ec2-user ~] npm install

The catalog AMI includes a Shell Script (build-app.sh) that automatically creates packages. When executed, it generates deployment zip files as follows:

# Execute Shell Script
./build-app.sh
  • .dist/api/sample-api.zip
  • .dist/event/sample-event.zip

2. Creating Deployment Bucket

Create a dedicated bucket to upload Lambda source code packages to an S3 bucket so they can be referenced from CloudFormation.

[ec2-user ~] AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
[ec2-user ~] AWS_REGION=us-east-1
[ec2-user ~] BUCKET_NAME="lambda-code-bucket-${AWS_REGION}-${AWS_ACCOUNT_ID}"

[ec2-user ~] aws s3api create-bucket \
--bucket $BUCKET_NAME \
--region $AWS_REGION \
--create-bucket-configuration "LocationConstraint=<your region>" # Add this option when creating in regions other than us-east-1

3. Uploading Deployment Packages to S3

Upload the source code packages to the created bucket

[ec2-user ~] aws s3 cp .dist/api/sample_api.zip s3://$BUCKET_NAME
[ec2-user ~] aws s3 cp .dist/event/sample_event.zip s3://$BUCKET_NAME