Solution:
I had a same problem - I deleted then re-installed a lambda function. My API Gateway was still indicating at the old one, so I had to go into the API Gateway and alter my Resource systems to alter the Integration Request setting to point to the new one .
You may have an problem in permission config, that's why API couldn't call your lambda. Attempt to apparently include to template.yaml file invoke
permission to your lambda from apigateway
as a principal
here's a sample below:
ConfigLambdaPermission:
Type: "AWS::Lambda::Permission"
DependsOn:
- MyApiName
- MyLambdaFunctionName
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref MyLambdaFunctionName
Principal: apigateway.amazonaws.com
I was having the similar issue however I was deploying through Terraform. Afterwards a suggestion from another user, I reselected my Lambda function in the Integration part of the API Gateway, and then checked what altered in my Lambda permissions. Turns out I required to include a "*" where I was putting the stage name in the source_arn section of the API Gateway trigger in my Lambda resource. Not sure how SAM compares to Terraform however probably you can alter the stage name or only attempt this troubleshooting technique that I attempted.
Similar error, and the solution was easy: clearing and employing the "Lambda Function" mapping again in the integration setting of the API Gateway.
My mapping seems like this: MyFunction-894AR653OJX:test
where "test" is the alias to point to the right version of my lambda
The issue was occured by removing the ALIAS "test" on the lambda, and recreating it on another version . It appears that the API gateway internally still connects to the `old' ALIAS instance. You would hope that the match is simply done on name.
Here is what my Lambda function policy JSON seemed like and the terraform:
"Principal": {
"Service": "apigateway.amazonaws.com"
},
"Action": "lambda:InvokeFunction",
"Resource": "arn:aws:lambda:us-east-1:999999999999:function:MY-APP",
"Condition": {
"ArnLike": {
"AWS:SourceArn": "arn:aws:execute-api:us-east-1:999999999999:d85kyq3jx3/*/POST/MY-APP"
}
}
}
]
}
add in a terraform like this:
//************************************************
// allows you to read in the ARN and parse out needed info, like region, and account
//************************************************
data "aws_arn" "api_gw_deployment_arn" {
arn = aws_api_gateway_deployment.MY-APP_deployment.execution_arn
}
//************************************************
// Add in this to support API GW testing in AWS Console.
//************************************************
resource "aws_lambda_permission" "apigw-post" {
statement_id = "AllowAPIGatewayInvokePOST"
action = "lambda:InvokeFunction"
//function_name = aws_lambda_function.lambda-MY-APP.arn
function_name = module.lambda.function_name
principal = "apigateway.amazonaws.com"
// "arn:aws:execute-api:us-east-1:473097069755:708lig5xuc/dev/POST1/cloudability-church-ws"
source_arn = "arn:aws:execute-api:${data.aws_arn.api_gw_deployment_arn.region}:${data.aws_arn.api_gw_deployment_arn.account}:${aws_api_gateway_deployment.MY-APP_deployment.rest_api_id}/*/POST/${var.api_gateway_root_path}"
}
Employ the API Gateway console
In the API Gateway console, select your API.
In the Resources pane, choose the HTTP system with the Lambda integration.
In the Method Execution pane, select Integration Request.
In the Integration Request pane, for HTTP system, select POST, and then choose the check mark icon (Update).
Deploy your API.
(Optional) Test the HTTP system with the Lambda integration.
Update your AWS CloudFormation template
In case you made your API employing a CloudFormation template, do the following:
- Update the template, assign the IntegrationHttpMethod property value to POST.
- Update the AWS CloudFormation stack with the template. This employment updates your API.
Update your OpenAPI definition
In case you made your API employing an OpenAPI definition, do the following:
Update the API definition, assign the httpMethod property value to POST. For more information, view x-amazon-apigateway-integration Object and the example Swagger template on the aws-samples GitHub repository.
Update your API by importing the updated API definition file into API Gateway.