【发布时间】:2018-07-22 07:07:28
【问题描述】:
我正在尝试编写一个 cloudformation 脚本,该脚本将创建一个 lambda 函数并将其连接到 API Gateway 代理资源。堆栈创建工作,但权限或集成配置有问题,当我测试端点时,我不断收到
2018 年 2 月 12 日星期一 06:45:28 UTC:端点响应正文之前 转换:无法 确定要授权的服务/操作名称
2018 年 2 月 12 日星期一 06:45:28 UTC:端点响应标头: {连接=保持活动状态, x-amzn-RequestId=4fdf1e92-0fc0-11e8-b3f1-0134476f962c, 内容长度=130,日期=星期一,2018 年 2 月 12 日 06:45:28 GMT} 2 月 12 日星期一 06:45:28 UTC 2018:由于配置错误,执行失败: 2018 年 2 月 12 日星期一 06:45:28 UTC 格式错误的 Lambda 代理响应:方法 完成状态:502
这是我的 cloudformation 脚本:
AWSTemplateFormatVersion: 2010-09-09
Description: An API that proxies requests to another HTTP endpoint
Resources:
MyFunction:
Type: 'AWS::Lambda::Function'
Properties:
Handler: samplefunction.lambda_handler
Runtime: python2.7
Code:
S3Bucket: "ilya-lambdas"
S3Key: "lambda-code.zip"
Role: 'arn:aws:iam::acc-id:role/service-role/basic_lambda_role'
Api:
Type: 'AWS::ApiGateway::RestApi'
Properties:
Name: foo3
Resource:
Type: 'AWS::ApiGateway::Resource'
Properties:
ParentId: !GetAtt Api.RootResourceId
RestApiId: !Ref Api
PathPart: 'test'
RootMethod:
Type: 'AWS::ApiGateway::Method'
Properties:
AuthorizationType: NONE
HttpMethod: ANY
ResourceId: !GetAtt Api.RootResourceId
RestApiId: !Ref Api
Integration:
IntegrationHttpMethod: ANY
IntegrationResponses:
- StatusCode: 200
SelectionPattern: .*
Type: AWS_PROXY
PassthroughBehavior: WHEN_NO_MATCH
Uri: !Join ["", ["arn:aws:apigateway:", "us-east-1", ":lambda:path/2015-03-31/functions/", !GetAtt MyFunction.Arn, "/invocations"] ]
Credentials: 'arn:aws:iam::acc-id:role/service-role/basic_lambda_role'
ProxyMethod:
Type: 'AWS::ApiGateway::Method'
Properties:
HttpMethod: ANY
ResourceId: !Ref Resource
RestApiId: !Ref Api
AuthorizationType: NONE
Integration:
IntegrationHttpMethod: ANY
IntegrationResponses:
- StatusCode: 200
SelectionPattern: .*
Type: AWS_PROXY
Uri: !Join ["", ["arn:aws:apigateway:", "us-east-1", ":lambda:path/2015-03-31/functions/", !GetAtt MyFunction.Arn, "/invocations"] ]
PassthroughBehavior: WHEN_NO_MATCH
Credentials: 'arn:aws:iam::acc-id:role/service-role/basic_lambda_role'
FunctionPermissions:
Type: "AWS::Lambda::Permission"
Properties:
Action: "lambda:InvokeFunction"
FunctionName: !GetAtt MyFunction.Arn
Principal: "apigateway.amazonaws.com"
SourceArn: !Join [ "", ["arn:aws:execute-api:", !Ref "AWS::Region", ":", !Ref "AWS::AccountId", ":", !Ref Api, "/*/*/*" ] ]
Deployment:
DependsOn:
- MyFunction
- RootMethod
- ProxyMethod
Type: 'AWS::ApiGateway::Deployment'
Properties:
RestApiId: !Ref Api
StageName: prod
我已经坚持了一段时间,任何指针将不胜感激。
【问题讨论】:
标签: amazon-web-services lambda aws-api-gateway amazon-cloudformation