【发布时间】:2020-07-02 18:53:46
【问题描述】:
我有一个有效的 API Gateway 与 SNS 集成,包括 API Gateway 的 CloudWatch 日志记录(这需要一些了解)。我现在需要的最后一部分是让 SNS 消息包含MessageAttributes。在 AWS 文档中寻找一个完整的示例似乎很困难/如果不是不可能的话……有人可以分享一个工作示例吗?
这是我目前所拥有的:
SfdcPlatformEventsApi:
Type: AWS::Serverless::Api
DependsOn:
- SfdcPlatformEventsApiLogGroup
Properties:
Name: !Sub '${EnvironmentName}-${ApplicationName}-api'
StageName: !Ref EnvironmentName
AccessLogSetting:
DestinationArn: !GetAtt SfdcPlatformEventsApiLogGroup.Arn
# 'requestId' is useless... but it is required for AccessLogSetting
Format: '{
"request_id": "$context.requestId",
"api_id": "$context.apiId",
"domain": "$context.domainPrefix"
"path": "$context.path",
"param": "$integration.request",
"http_method": "$context.httpMethod",
"source_ip": "$context.identity.sourceIp",
"user-agent": "$context.identity.userAgent",
"api_key": "$context.identity.apiKey",
"status": "$context.status",
"responseLatency": "$context.responseLatency",
"requestTime": "$context.requestTime",
"wafResponseCode": "$context.wafResponseCode",
"xrayTraceId": "$context.xrayTraceId",
"error_message": "$context.error.message",
"error.validationErrorString": "$context.error.validationErrorString"
}'
MethodSettings:
- DataTraceEnabled: true
HttpMethod: '*'
LoggingLevel: INFO
ResourcePath: '/*'
MetricsEnabled: true
# enable xRay tracing
TracingEnabled: true
DefinitionBody:
swagger: 2.0
info:
title: !Sub '${EnvironmentName}-${ApplicationName}-api'
paths:
/{proxy+}:
post:
responses:
'202':
description: 'Published'
x-amazon-apigateway-integration:
type: aws
httpMethod: POST
uri: !Sub 'arn:aws:apigateway:${AWS::Region}:sns:action/Publish'
credentials: !GetAtt SfdcPlatformEventsApiRole.Arn
parameters:
name: proxy
in: path
required: true
type: string
requestParameters:
method.request.path.proxy: true
integration.request.querystring.Type: 'method.request.body.attributes.type'
integration.request.querystring.MessageAttributes: 'method.request.body.attributes'
integration.request.querystring.Message: 'method.request.body'
integration.request.querystring.TopicArn: !Sub "'${SfdcPlatformEventsSnsQueue}'" #It looks funky here with the double and single quotes!! But it needs it!
responses:
default:
statusCode: 202
security:
- API_KEY: []
x-amazon-apigateway-api-key-source: HEADER
x-amazon-apigateway-gateway-responses:
ACCESS_DENIED:
statusCode: 403
responseTemplates:
application/json: !Ref AccessDeniedMsg
securityDefinitions:
API_KEY:
type: 'apiKey'
name: 'x-api-key'
in: 'header'
【问题讨论】:
标签: amazon-web-services aws-api-gateway amazon-sns openapi