在CloudFormation中添加以下资源:
  MyApi:
    Type: 'AWS::ApiGateway::RestApi'
    Properties:
      Name: my-api
      Body:
        swagger: '2.0'
        info:
          title: my-api
          version: 1.0.0
        paths:
          /my-resource:
            get:
              responses:
                '200':
                  description: 200 response
              x-amazon-apigateway-integration:
                uri: !Sub
                  - arn:aws:apigateway:${AWS::Region}:sqs:path/${AwsAccountId}/${QueueName}
                  - AwsAccountId: YOUR_ACCOUNT_ID # Replace this with your AWS account ID
                    QueueName: YOUR_QUEUE_NAME # Replace this with your queue name
                passthroughBehavior: when_no_templates
                httpMethod: POST
                type: aws_proxy
在uri字段中,ARN要指向具有一组存储消息的SQS队列,代理集成的类型应为aws_proxy。
注意:CloudFormation不支持向ARN添加${AWS::Region},因此不需要在ARN中添加它。
下一篇:API代理遭遇缓冲区溢出