Here are the steps to configure API Gateway for integrated
website.
Step 1: Create Rest API shown as below.
Step 2: Create resource as “proxy’.
Step 3: Create method as “Any” type
The method type is “Any”, so all the functions behind the
Lambda either get or post will work within API. The invocation of the lambda
function is dynamic. Define stage variable in place of lambda function name.
On click of Save, AWS will ask to add permission to Lambda
function that can be executable by API gateway. Replace the value of ${stageVariables.functionname}
to the lambda function
name. Execute below command to CLI.
aws lambda add-permission --function-name
"arn:aws:lambda:ap-south-1:518955882229:function:${stageVariables.functionname}"
--source-arn
"arn:aws:execute-api:ap-south-1:518955882229:u5ismynmx3/*/*/*"
--principal apigateway.amazonaws.com --statement-id
c7210776-beb6-4aad-bcfa-fdb20972f52f --action lambda:InvokeFunction
Step 4: Deploy API
Create stages of API gateway like Stage and Prod.
Step 5: Assign lambda function to variable
Select the created stage. In stage variables, add new stage
variable with name “functionname” and value “your lambda function”.