Before deploying the CloudFormation stack, you need to package the Lambda source code and upload it to an S3 bucket. AWS SAM will reference this artifact during deployment.
Navigate to the code_protector_aws directory and install Node.js dependencies:
cd code_protector_aws
npm install
Verify that node_modules/ is created and no installation errors occur.
Create an S3 bucket in your target region to store the Lambda deployment artifact. This bucket is separate from the application buckets (which SAM will create).
aws s3 mb s3://DEPLOY_BUCKET --region REGION
Replace
DEPLOY_BUCKETandREGIONwith your values from the Prerequisites section.Example:
aws s3 mb s3://guardscript-deploy-ap-southeast-1 --region ap-southeast-1
Verify the bucket exists:
aws s3 ls | grep DEPLOY_BUCKET
Create a ZIP archive of the Lambda source code. The archive must include the src/ folder and node_modules/.
On Linux / macOS:
zip -r lambda.zip src/ node_modules/ package.json
On Windows (PowerShell):
Compress-Archive -Path src, node_modules, package.json -DestinationPath lambda.zip -Force
Verify the ZIP file was created:
ls -lh lambda.zip # Linux/macOS
# or
Get-Item lambda.zip # PowerShell
Upload the artifact to the deployment bucket:
aws s3 cp lambda.zip s3://DEPLOY_BUCKET/lambda.zip
Verify the upload:
aws s3 ls s3://DEPLOY_BUCKET/
You should see lambda.zip listed with its size and upload timestamp.
At the end of this phase you have:
DEPLOY_BUCKET)lambda.zip from src/ + node_modules/lambda.zip to s3://DEPLOY_BUCKET/lambda.zipProceed to Phase 2: Deploy AWS Infrastructure.