简体   繁体   English

如何使用 Ansible 将 AWS API 网关集成请求正确设置为 lambda 函数?

[英]How to set AWS API gateway integration request to lambda function correctly using Ansible?

I'm trying to create a straightforward Python lambda function connected to API gateway using Ansible.我正在尝试使用 Ansible 创建一个直接连接到 API 网关的 Python lambda 函数。 I've got everything setup to work correctly, except the API gateway always adds a colon and an integer to the lambda function arn.除了 API 网关总是在 lambda 函数 arn 中添加一个冒号和一个整数之外,我已经设置了一切正常工作。 When calling the API, I get internal server error.调用 API 时,出现内部服务器错误。 If I simply remove this additional integer (the version number I believe) on the web console and redeploy I get the expected response when calling the API.如果我只是在 Web 控制台上删除这个额外的整数(我相信的版本号)并重新部署,我会在调用 API 时得到预期的响应。 However, I'd really like to have this fully automatic with Ansible, but can't see how to correctly choose the lambda function version when setting up the API gateway.但是,我真的很想在 Ansible 中实现全自动,但是在设置 API 网关时看不到如何正确选择 lambda 函数版本。 How do I set the lambda function name for the API gateway in Ansible, without it appending a version number?如何在 Ansible 中为 API 网关设置 lambda 函数名称,而不附加版本号?

Ansible code: Ansible代码:

- name: Create API gateway
  aws_api_gateway:
    state: present
    aws_access_key: "{{ aws_access_key_id }}"
    aws_secret_key: "{{ aws_secret_access_key }}"
    region: "{{ aws_region }}"
    swagger_file: roles/aws-api-proxy/templates/swagger_complete.j2
    stage: production
    deploy_desc: Production Deployment
  register: apigateway_result

My swagger file:我的招摇文件:

---
swagger: "2.0"
info:
  version: "2017-10-27T10:39:47Z"
  title: "apiproxyfunction"

basePath: "/prod"
schemes:
- "https"
paths:
  /submit:
    post:
      produces:
      - "application/json"
      responses:
        200:
          description: "200 response"
          schema:
            $ref: "#/definitions/Empty"
      x-amazon-apigateway-integration:
        responses:
          default:
            statusCode: "200"
                 uri: "arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/{{ lambda_result.configuration.function_arn }}/invocations"
        passthroughBehavior: "when_no_match"
        httpMethod: "POST"
        contentHandling: "CONVERT_TO_TEXT"
        type: "aws_proxy"
definitions:
  Empty:
    type: "object"
    title: "Empty Schema"

The {{ lambda_result.configuration.function_arn }} variable is taken from when I create the lambda function which is like this: {{ lambda_result.configuration.function_arn }} 变量取自我创建 lambda 函数时,如下所示:

arn:aws:lambda:eu-west-1:MYACCOUNTID:function:apiproxyfunctionXYZ

However, in the web console, the API gateway resource section;但是,在 Web 控制台中,API 网关资源部分; lambda integration request Lambda Function ends up being- apiproxyfunctionXYZ:1 lambda 集成请求 Lambda 函数最终变成了 - apiproxyfunctionXYZ:1

So how to remove the :1?那么如何删除:1? Or is there another workaround?或者还有其他解决方法吗?

Please ask if you need more background details.请询问您是否需要更多背景信息。

EDIT - see screenshot of console FYI.编辑 - 请参阅控制台截图。

在此处输入图片说明

- name: Set lambda_arn fact
  set_fact:
    lambda_arn: "{{ lambda_data.configuration.function_arn.split(':')[0:7] | join(':') }}"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有API网关集成的AWS Lambda-访问api名称和http请求的类型 - aws lambda with API gateway integration - accessing api name and type of http request 无法使用 API Gateway 运行 AWS Lambda 函数 - Unable to run AWS Lambda function with API Gateway AWS CDK 如何在网关 lambda 集成的请求模板中嵌入自定义 java 脚本 - AWS CDK how to embed custom java script in request template of gateway lambda Integration 集成lambda函数或每个api网关http代码的拆分lambda - integration lambda function or split lambda per api gateway http codes API网关中的AWS Lambda集成响应 - {“message”:“内部服务器错误”} - AWS Lambda Integration Response in API Gateway - {“message”: “Internal server error”} 如何使用 Boto3 修改 API 网关集成请求 - How to modify API gateway integration request using Boto3 How do you format Python using json.dumps, to make your Lambda function respond correctly to API Gateway? - How do you format Python using json.dumps, to make your Lambda function respond correctly to API Gateway? 如何使用 multipart/form-data 创建一个将 pdf 文件作为输入的 AWS Lambda/API 网关 python 函数? - How to create an AWS Lambda/API gateway python function that takes a pdf file as input using multipart/form-data? 如何配置serverless.yml或AWS API网关或AWS Lambda处理程序以从POST请求读取request.header - How to configure serverless.yml or AWS API gateway or AWS lambda handler to read request.headers from POST request 使用API​​网关尝试AWS Python Lambda函数中的访问参数时出错 - Error when trying access parameters in AWS Python Lambda function using API Gateway
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM