Creating Stages in API Gateway& Adding Alias in Lambda.

sravanthi vallepu
Jul 19 · 8 min read
import json
import os
def lambda_handler(event, context):
global processing_environment
function_name = context.function_name
function_arn = context.invoked_function_arn
alias = function_arn.split(":").pop()
if alias != "qa" and alias != "prod":
alias = "dev"
# END - Following code is ued for calling appropriate environment variables #
environment = os.environ[alias + '_targetEnvironment']
processing_environment = alias
return {
'statusCode': 200,
'body': json.dumps('Hello from QA Lambda!')
}
aws lambda add-permission           
--function-name "arn:aws:lambda:us-west-2:************:function:test_lambda:${stageVariables.lambdaAlias}" --source-arn "arn:aws:execute-api:us-west-2:************/*/POST/test"
--principal apigateway.amazonaws.com
--statement-id e********-***e-*ffa-*d6c-**********
--action lambda:InvokeFunction
aws lambda add-permission  
--function-name "arn:aws:lambda:us-west-2:***********:function:test_lambda:dev"
--source-arn "arn:aws:execute-api:us-west-2:***************/*/*/test"
--principal apigateway.amazonaws.com
--statement-id e*******-***e-*ffa-****-************
--action lambda:InvokeFunction
aws — version.aws configureAWS Access Key ID [****************4BNQ]: Here you have to add Access keyAWS Secret Access Key [****************XuyH]: Here you have to add Secret Access KeyDefault region name [us-west-2]: Here you have to add regionDefault output format [JSON]: Here you have to add formatAdd the copied Aws permission function in the command prompt.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade