如何解决AWS API Gateway 与 Cloudformation 脚本中的 AWS Event Bridge(Cloudwatch Events) 集成
原始要求:
在 AWS Api Gateway 上创建一个路由/路径,将 API Gateway 直接连接到 AWS Event Bridge (Cloudwatch Events) 并将事件放置/推送到它的事件总线上。
能够创建它并在从 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 的值应该如下:
对于 AWS 或 AWS_PROXY 集成,URI 的格式为 arn:aws:apigateway:{region}:{subdomain.service|service}:path|action/{service_api}。此处,{Region} 是 API 网关区域(例如,us-east-1); {service} 是集成 AWS 服务的名称(例如,s3); {subdomain} 是某些 AWS 服务支持的指定子域,用于快速查找主机名。 action 可用于基于 AWS 服务操作的 API,使用 Action={name}&{p1}={v1}&p2={v2}... 查询字符串。随后的 {service_api} 指的是受支持的操作 {name} 以及任何必需的输入参数。或者,路径可用于基于 AWS 服务路径的 API。随后的 service_api 指的是 AWS 服务资源的路径,包括集成 AWS 服务的区域(如果适用)。例如,为了与 Getobject 的 S3 API 集成,uri 可以是 arn:aws:apigateway:us-west-2:s3:action/Getobject&Bucket={bucket}&Key={key} 或 arn:aws:apigateway: us-west-2:s3:path/{bucket}/{key}
您一定已经注意到,我将上述 uri 中的 service 替换为 cloudwatchEvents。
现在,在发布 API 网关期间 AWS Cloudformation 控制台给出错误:
不支持 cloudwatchEvents 类型的 AWS 服务(服务:AmazonApiGateway;状态代码:400;错误代码:BadRequestException;请求 ID:07bae22c-d198-4595-8de9-6ea23763eff5;代理:null)
现在我尝试用
替换服务- 云观察
- eventBridge
- cloudwatchEvent
- 事件总线
这才是真正的问题。我应该在 uri 中放置什么才能接受?
解决方法
根据评论,
事件的 URI 应如下所示:
arn:aws:apigateway:${AWS::Region}:events:action/PutEvents
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。