[英]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.