Using Versions/Aliases
We need to make some modifications to version 4.1 of this package. In AWS Lambda, we've saved a new version as we don't want to modify the working version used in production.
How can use our new version 2 in our "staging" environment requests?
Is the only solution to deploy a new Cloudformation and modify test there?
@thadallender Thanks for contacting us. May I ask you which "new version 2" you are talking about? Or do you want to update your AWS Lambda function with your own update?
Yes, I want to use my own code for “version 2” in Lambda.
On Feb 17, 2020, at 12:42 PM, Beomseok Lee [email protected] wrote:
@thadallender Thanks for contacting us. May I ask you which "new version 2" you are talking about? Or do you want to update your AWS Lambda function with your own update?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
@thadallender ,
The simplest solution is to execute npm run build at /YOUR_PATH/serverless-image-handler/source/image-handler. Then you will see image-handler.zip file at /YOUR_PATH/serverless-image-handler/source/image-handler/dist. You can upload that file to your AWS Lambda function.
Thanks. I understand how to update Lambda code. I don’t want Lambda to use $LATEST version. I need to use Lambda Versions/Alias feature to test my code and not just deploy to production.
How do we do this with this package?
On Feb 17, 2020, at 12:49 PM, Beomseok Lee [email protected] wrote:
@thadallender , The simplest solution is to execute npm run build at /YOUR_PATH/serverless-image-handler/source/image-handler. Then you will see image-handler.zip file at /YOUR_PATH/serverless-image-handler/source/image-handler/dist. You can upload that file to your AWS Lambda function.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
Oh, sorry @thadallender I misunderstood your initial question. This would be the steps you can follow.
- On the AWS Lambda function,
<<YOUR_STACK>>-ImageHandlerFunction-<<HASH>>, click "Public new version". - Click "Create alias", and create 2 aliases: DEV with $LATEST version and PROD with the version you created. You would see something similar to the below image.

- On the Amazon API Gateway console, select the
ServerlessImageHandlerAPI, and click "Resources" menu. - Click
ANYmethod, and click "Integration Request". - Change the Lambda Function value to
<<YOUR_LAMBDA_FUNCTION_NAME>>:${stageVariables.alias}. You will see the popup which says to "Add Permission to Lambda Function". - Copy and paste the CLI command, and add permissions by changing
${stageVariables.alias}toDEVandPRODusing AWS CLI. For example,aws lambda add-permission --function-name "<<YOUR_LAMBDA_FUCNTION_ARN>>:DEV" --source-arn "<<YOUR_API_GATEWAY_ARN>>/*/*/*" --principal apigateway.amazonaws.com --statement-id <<YOUR_STATEMENT_ID>> --action lambda:InvokeFunction - Select "Deploy API" on Amazon API Gateway console, and choose "[New Stage]". On "Stage name", you can provide something like "dev". Then click "Deploy" button.
- On Stages menu, click "image", and click "Stage Variables" tab. Click "Add stage Variable".

- Click the other stage you created, for example "dev", and add stage variables as well, but you need to change the value to "DEV".
- Go to the AWS Lambda console, and select $LATEST version, and upload your new source code.
After following the above steps, the expected output is that when you access to "dev" stage URL, you would see the latest source code. Your current Amazon CloudFront distribution URL would not deploy the latest source code as your AWS Lambda function PROD alias does not have the latest version.
For your reference, you can read this blog post as well.
I hope this would solve your issue, and even though I've tested my environment with the above steps, please make sure to test the above step before adapting into your environment.
@thadallender does this answer your question?
@thadallender if the issue still relevant, please feel free to reopen the issue.