Assignment:
Build API Gateway with different stages using stage variables
Step: #1 create instance to run CLI commands and perform actions
related to the API Gateway and Lambda functions.
Step: 2: Create two Lambda Functions:
why create two functions:
In this task, two Lambda functions named TestingLambda and ProductionLambda are created to
separate the testing and production environments. The TestingLambda function is used to test and
verify the application logic without affecting the live system, while the ProductionLambda function is
used to handle real user requests in the production environment. These Lambda functions will later be
integrated with API Gateway to process HTTP requests and return responses. This approach helps in safe
testing, error handling, and maintaining system stability.
stpes:
Select Author from Scratch
Function Name : Enter ProductionLambda
Runtime : Select Python 3.12
Expand Change default execution role
Execution Role : and choose BasicLambdaRole
After that I have customize son code according to my requirements
and deploy successfully:
after that I have created another function name is testlamda follow same
steps
Q:: why created two functions whats is production lamda work and
teslamda ?
ProductionLambda usually:
Receives real HTTP requests from API Gateway
Runs final business logic
Connects to real database
Saves / updates real data
Returns real responses to users
estingLambda usually:
Receives test requests from API Gateway or PostmanRuns . test version of your code
Returns sample or dummy responses
Logs detailed error messages
May use test database or mock data:
created TestingLamda successfully and deploy
Step: 3 : Create an API:
why do we create API ?
Allow communication between systems
Browser / Mobile app / Postman
API Gateway
Lambda function
Database:
Users or applications cannot directly call Lambda or [Link]
send a request to the API, and the API sends it to Lambda.
lets create :
hoose create new API as New API, Under settings, choose the API name
MyAPI. Leave other options as default and click on Create API.
Select REST: because perfume CRUD opreations
Creating a Resource:
creating a resource within the API. In this case, the resource will be used to define the endpoint for
accessing the Lambda functions.
name is myresource.
next I have Created a Method:
he method, specifically a GET method, will be integrated with the Lambda functions using the
Lambda Proxy integration.
Choose Get mothod
integration type lamda function
stage : ${[Link]}
Run the CLI command to give lambda permissions to the API using the
EC2 instance which created in step 1 :to run the CLI command to give
lambda permissions to the API using :
1st I have ssh :
after that run aws configure after this command I have put acess and
screte key
after that enter region
press enter and next run command is echo STATEMENT_ID=$(uuidgen)
press entre generate ID
After that run : STATEMENT_ID="my_statement_id_$(date +
%s)" # This appends current timestamp to the statement ID
to combine informations:
and next run: aws lambda add-permission \
--function-name "arn:aws:lambda:us-east-
1:970223424793:function:ProductionLambda" \
--source-arn "<YOUR_API_GATEWAY_ARN>" \
--principal [Link] \
--statement-id "apigateway-invoke-productionlambda" \
--action lambda:InvokeFunction \
--region us-east-1
run the same command but change the function name
Deploy API Gateway with two different stages:
deploying the API Gateway with two different stages: TestingAPI and ProductionAPI. These stages
provide separate environments for testing and production.
Same methods follow for ProductionAPI :
Next need to Add stage variables to both stages
The stage variables will be used to define the specific Lambda functions associated with
each stage.
1st add testing variable
2nd add production variable
Test the API Gateway
to test the API Gateway by making GET requests to the endpoints associated with the deployed
stages. This ensures that the API Gateway is properly integrated with the Lambda functions and
functioning as expected.
Want to copt invoke url test on browser :I have click on get method
recive link: [Link]
[Link]/ProductionAPI/myresource
past link on browser get error .