I am trying to put template in API Gate Way with next command:
aws apigateway put-rest-api --rest-api-id $APIGW --mode merge --body 'fileb://./api-gw-template.json'
Template is:
{
"swagger" : "2.0",
"basePath" : "/aws",
"schemes" : [ "https" ],
"paths" : {
"/{proxy+}" : {
"x-amazon-apigateway-any-method" : {
"parameters" : [ {
"name" : "proxy",
"in" : "path",
"required" : true,
"type" : "string"
} ],
"responses" : { },
"x-amazon-apigateway-integration" : {
"httpMethod" : "POST",
"uri" : "{{URI}}",
"responses" : {
"default" : {
"statusCode" : "200"
}
},
"passthroughBehavior" : "when_no_match",
"cacheNamespace" : "2wn7w2",
"cacheKeyParameters" : [ "method.request.path.proxy" ],
"contentHandling" : "CONVERT_TO_TEXT",
"type" : "aws_proxy"
}
}
}
},
"x-amazon-apigateway-binary-media-types" : [ "font/woff", "image/x-icon", "*/*" ]
}
This template creates a proxy resource with lambda integration, everything is fine here. But in my lambda function, I don't see a new trigger for that resource. But if I create the same resource manually, the trigger in the lambda is also created. And if I export these two api gateway as swagger json template they are the same.
Also deploy api after import template doesn't help. Here is output after import templat:
{
"id": "********",
"name": "Imported on 2022-09-14T12:09:17Z",
"createdDate": 1663149628,
"warnings": [
"Required \"info\" property is missing from the document root."
],
"binaryMediaTypes": [
"font/woff",
"image/x-icon",
"*/*"
],
"apiKeySource": "HEADER",
"endpointConfiguration": {
"types": [
"REGIONAL"
]
},
"policy": "{\\\"Version\\\":\\\"2012-10-17\\\",\\\"Statement\\\":[{\\\"Effect\\\":\\\"Allow\\\",\\\"Principal\\\":\\\"*\\\",\\\"Action\\\":\\\"execute-api:Invoke\\\",\\\"Resource\\\":\\\"arn:aws:execute-api:eu-central-1:*************:***********\\/*\\/*\\/*\\\"}]}",
"disableExecuteApiEndpoint": false
}
aws apigateway put-integration
command also don't create trigger in lambda
Can someone help me? Where is my mistake?
I found the solution myself. The lambda function needs permission to be able to be called by the API gateway integration.
Solution in my case (if you are using a resource without a proxy - specify the resource name instead of the last asterisk in the "--source-arn" key):
aws lambda add-permission --function-name $lambda \
--statement-id apigateway-test-111111 --action lambda:InvokeFunction \
--principal apigateway.amazonaws.com \
--source-arn "arn:aws:execute-api:$REGION_NAME:$ACCOUNT:$APIGW/*/*/*"
When manually creating a resource, this permission is automatically created
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.