Description: API Gateway integration with SQS Outputs: ApiEndpoint: Description: Endpoint for this stage of the api Value: !Join - '' - - https:// - !Ref 'APIGateway' - .execute-api. - !Ref 'AWS::Region' - .amazonaws.com/ - prod QueueArnSQS: Description: ARN of SQS Queue Value: !GetAtt 'DestQueue.Arn' Parameters: queueName: Description: The name of the SQS queue to create. Type: String Resources: APIGateway: Properties: Description: API Endpoint to receive JSON payloads and queue in SQS Name: APIGateway Type: AWS::ApiGateway::RestApi APIGatewayRole: Properties: AssumeRolePolicyDocument: Statement: - Action: - sts:AssumeRole Effect: Allow Principal: Service: - apigateway.amazonaws.com Version: '2012-10-17' Path: / Policies: - PolicyDocument: Statement: - Action: sqs:SendMessage Effect: Allow Resource: !GetAtt 'DestQueue.Arn' - Action: - logs:CreateLogGroup - logs:CreateLogStream - logs:PutLogEvents Effect: Allow Resource: '*' Version: '2012-10-17' PolicyName: apig-sqs-send-msg-policy RoleName: apig-sqs-send-msg-role Type: AWS::IAM::Role DestQueue: Properties: DelaySeconds: 0 MaximumMessageSize: 262144 MessageRetentionPeriod: 1209600 QueueName: !Ref 'queueName' ReceiveMessageWaitTimeSeconds: 0 VisibilityTimeout: 30 Type: AWS::SQS::Queue PolicySQS: Properties: PolicyDocument: Statement: - Action: SQS:* Effect: Allow Principal: '*' Resource: !GetAtt 'DestQueue.Arn' Sid: Sid1517269801413 Version: '2012-10-17' Queues: - !Ref 'DestQueue' Type: AWS::SQS::QueuePolicy PostMethod: Properties: AuthorizationType: NONE HttpMethod: POST Integration: Credentials: !GetAtt 'APIGatewayRole.Arn' IntegrationHttpMethod: POST IntegrationResponses: - StatusCode: '200' PassthroughBehavior: NEVER RequestParameters: integration.request.header.Content-Type: '''application/x-www-form-urlencoded''' RequestTemplates: application/json: Action=SendMessage&MessageBody=$input.body Type: AWS Uri: !Join - '' - - 'arn:aws:apigateway:' - !Ref 'AWS::Region' - :sqs:path/ - !Ref 'AWS::AccountId' - / - !Ref 'queueName' MethodResponses: - ResponseModels: application/json: Empty StatusCode: '200' ResourceId: !Ref 'enqueueResource' RestApiId: !Ref 'APIGateway' Type: AWS::ApiGateway::Method enqueueResource: Properties: ParentId: !Ref 'v1Resource' PathPart: enqueue RestApiId: !Ref 'APIGateway' Type: AWS::ApiGateway::Resource prodDeployment: DependsOn: PostMethod Properties: RestApiId: !Ref 'APIGateway' Type: AWS::ApiGateway::Deployment prodStage: Properties: DeploymentId: !Ref 'prodDeployment' RestApiId: !Ref 'APIGateway' StageName: prod Type: AWS::ApiGateway::Stage v1Resource: Properties: ParentId: !GetAtt 'APIGateway.RootResourceId' PathPart: v1 RestApiId: !Ref 'APIGateway' Type: AWS::ApiGateway::Resource