AWS API Cloudformation 脚本中与 AWS Event Bridge(Cloudwatch Events) 的网关集成

AWS API Gateway integration with AWS Event Bridge(Cloudwatch Events) in Cloudformation Script

原始要求

在 AWS Api 网关上创建一个 route/path 网关,它将 API 网关直接连接到 AWS Event Bridge (Cloudwatch Events) 和它的事件总线上的 [​​=60=] 事件.

能够创建它并在从 AWS 控制台完成时执行得很好。

实际问题

为这个 API 网关编写 AWS Cloudformation 脚本时,它看起来像这样:

EventsPostMethod:
 Type: AWS::ApiGateway::Method
 Properties:
   ResourceId:
     Ref: EventsResource
 RestApiId:
   Ref: RestAPI
 HttpMethod: POST
 AuthorizationType: NONE
 Integration:
   Type: AWS
   IntegrationHttpMethod: POST
   Uri:
     Fn::Sub: arn:aws:apigateway:${AWS::Region}:cloudwatchEvents:action/PutEvents
   RequestParameters:
     integration.request.header.X-Amz-Target: "'AWSEvents.PutEvents'"
   RequestTemplate:
     some-script-here...
   

注意 Uri 值:

"arn:aws:apigateway:${AWS::Region}:cloudwatchEvents:action/PutEvents"
arn:aws:apigateway:{region}:{subdomain.service|service}:path|action/{service_api}

根据 AWS Docs uri 的值应如下所示:

For AWS or AWS_PROXY integrations, the URI is of the form arn:aws:apigateway:{region}:{subdomain.service|service}:path|action/{service_api}. Here, {Region} is the API Gateway region (e.g., us-east-1); {service} is the name of the integrated AWS service (e.g., s3); and {subdomain} is a designated subdomain supported by certain AWS service for fast host-name lookup. action can be used for an AWS service action-based API, using an Action={name}&{p1}={v1}&p2={v2}... query string. The ensuing {service_api} refers to a supported action {name} plus any required input parameters. Alternatively, path can be used for an AWS service path-based API. The ensuing service_api refers to the path to an AWS service resource, including the region of the integrated AWS service, if applicable. For example, for integration with the S3 API of GetObject, the uri can be either arn:aws:apigateway:us-west-2:s3:action/GetObject&Bucket={bucket}&Key={key} or arn:aws:apigateway:us-west-2:s3:path/{bucket}/{key}

你一定注意到我在上面提到的uri中用cloudwatchEvents替换了service

现在,AWS Cloudformation 控制台在 API 网关发布期间给出错误:

AWS Service of type cloudwatchEvents not supported (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: 07bae22c-d198-4595-8de9-6ea23763eff5; Proxy: null)

现在我尝试用

替换服务

这才是真正的问题。我应该在 uri 的服务中放置什么以便它接受?

根据评论,

事件的 URI 应如下所示:

arn:aws:apigateway:${AWS::Region}:events:action/PutEvents