I have an AWS serverless recipe that is working fine except for creating A POST method to hook straight to SNS, which is possible via the console. The relevant resource definition is
GatewayResourceApiPost:
Type: AWS::ApiGateway::Method
Properties:
HttpMethod: POST
ResourceId: !Ref GatewayResourceApi
RestApiId: !Ref Gateway
ApiKeyRequired: false
AuthorizationType: "NONE"
Integration:
RequestParameters:
integration.request.header.Content-Type: "application/x-www-form-urlencoded"
IntegrationHttpMethod: POST
Type: AWS
Uri: "arn:aws:apigateway:${self:provider.region}:sns:action/Publish"
Credentials: !Ref IamRoleGatewayExecution
PassthroughBehavior: WHEN_NO_MATCH
sls deploy returns following error
An error occurred: GatewayResourceApiPost - Invalid ARN specified in the request (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: 4fa6a8ff-1128-4213-a774-d1bdfc66081e; Proxy: null)
The resultant cloudformation-template-update-stack.json contains the following resource section
"GatewayResourceApiPost": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"HttpMethod": "POST",
"ResourceId": {
"Ref": "GatewayResourceApi"
},
"RestApiId": {
"Ref": "Gateway"
},
"ApiKeyRequired": false,
"AuthorizationType": "NONE",
"Integration": {
"RequestParameters": {
"integration.request.header.Content-Type": "application/x-www-form-urlencoded"
},
"IntegrationHttpMethod": "POST",
"Type": "AWS",
"Uri": "arn:aws:apigateway:eu-west-2:sns:action/Publish",
"Credentials": {
"Ref": "IamRoleGatewayExecution"
},
"PassthroughBehavior": "WHEN_NO_MATCH"
}
}
},
If I remove the Integration part, the resource is created with no method as expected.
By way of comparison, I manually created the resource in the console, deployed to a stage and downloaded the definition.
openapi: "3.0.1"
info:
title: "Gateway"
version: "2020-12-29T08:27:11Z"
servers:
- url: "https://*********.execute-api.eu-west-2.amazonaws.com/{basePath}"
variables:
basePath:
default: "/dev"
paths:
/api:
post:
x-amazon-apigateway-integration:
credentials: "arn:aws:iam::**********:role/gateway-cloud-poc-poc-IamRoleGatewayExecution-18ER9Q32F4YXN"
uri: "arn:aws:apigateway:eu-west-2:sns:action/Publish"
responses:
default:
statusCode: "200"
passthroughBehavior: "when_no_match"
httpMethod: "POST"
type: "aws"
components: {}
Is this a known issue for serverless, or am I missing some secret sauce to make this work?
Any help appreciated.
sls --version
Framework Core: 1.83.2 (local)
Plugin: 3.8.4
SDK: 2.3.2
Components: 2.34.9