amazon-web-services - 无法使用 CloudFormation 让 API 代理与 SQS 一起使用
问题描述
我正在学习本教程,我可以使用控制台让这一切正常工作。我已将 SQS 队列和 API 创建转换为 CloudFormation,但无法使 API 方法集成正常工作。我已使用Former2 将工作方法转换为CloudFormation(如下所示),但我继续收到此错误:
Invalid mapping expression specified: Validation Result:
warnings : [],
errors : [Invalid mapping expression specified: application/x-www-form-urlencoded]
(Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException;
Request ID: 1e40fc86-af05-4698-a91a-c1fa8930ee10; Proxy: null)
我的 POST 方法的 CloudFormation 模板如下:
ApiPostMsgMethod:
DependsOn: 'SqsQueue'
Type: AWS::ApiGateway::Method
Properties:
ApiKeyRequired: false
AuthorizationType: NONE
HttpMethod: POST
Integration:
Credentials: !GetAtt ApiSqsSendMsgRole.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'
TimeoutInMillis: 1200
Type: AWS
Uri: !Join
- ""
- - !Sub "arn:aws:apigateway:${AWS::Region}:sqs:path/${AWS::AccountId}/"
- !Sub ${EnvironmentName}-queue
MethodResponses:
- StatusCode: 200
OperationName: PostSqsItem
ResourceId: !Ref SqsResource
RestApiId: !Ref SqsRestApi
而Former2从一个工作的POST方法返回以下模板:
httpMethod: POST
authorizationType: NONE
apiKeyRequired: false
requestParameters: <empty object>
methodResponses:
200:
statusCode: 200
responseModels:
application/json: Empty
methodIntegration:
type: AWS
httpMethod: POST
uri: arn:aws:apigateway:###:sqs:path/###/###
credentials: arn:aws:iam::###:role/###
requestParameters:
integration.request.header.Content-Type: 'application/x-www-form-urlencoded'
requestTemplates:
application/json: Action=SendMessage&MessageBody=$input.body
passthroughBehavior: NEVER
timeoutInMillis: 29000
cacheNamespace: ###
integrationResponses:
200:
statusCode: 200
responseTemplates:
restApiId: ###
resourceId: ###
我的引用和替换似乎正在工作,但我仍然收到此集成错误。我错过了什么吗?
解决方案
我认为在我看来麻烦来自这里
integration.request.header.Content-Type: 'application/x-www-form-urlencoded'
它应该是这样的
integration.request.header.Content-Type: "'application/x-www-form-urlencoded'"
推荐阅读
- kubernetes - Kubernetes 动态卷供应的效率如何?
- python - 编写多个字典介绍 csv 文件
- jmeter - 如何将 Jenkins 与 Jmeter 集成
- solr - Solr上查询,限制每天的行数
- r - rstan C++14 安装时出错(centos)
- java - 哪个java库可以创建这样的pdf文件?
- javascript - 如何在反应 ag-grid 中验证行选择?
- java - 解析日期时间时出错,带有有效时间戳的 DateTimeParseException
- mysql - 从 3 个不同的列中选择不同的记录
- vb.net - 如何将字符串转换为时间跨度?视觉基础,秒表,圈系统