简体   繁体   English

我想在API URL字符串中传递EC2实例ID以使用Lambda函数停止EC2实例

[英]I want pass EC2 instance ID in the API URL string to stop EC2 instance using Lambda Function

I have Python code to stop EC2 instances in AWS using lambda function from this link . 我有Python代码可以使用来自此链接的 lambda函数在AWS中停止EC2实例。 This Python 2.7 code is working fine when I am using with the Lambda function. 当我与Lambda函数一起使用时,此Python 2.7代码可以正常工作。

The lambda function to stop instances also can be executed from the API endpoint. 也可以从API端点执行停止实例的lambda函数。

Now how can I stop instances by providing an instance id with the API endpoint in browser instead to provide in the Python code? 现在如何通过在浏览器中为API端点提供实例ID而不是在Python代码中提供实例ID来停止实例?

Can anyone help me on this? 谁可以帮我这个事?

You can pass the instance id in the payload (assuming you are using POST) from API gateway to Lambda. 您可以将有效负载中的实例ID(假设您正在使用POST)从API网关传递给Lambda。 Read that payload in Lambda, parse the instance id and use that. 在Lambda中读取该有效负载,解析实例ID并使用它。 That's it. 而已。

See this for more details http://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started.html#getting-started-new-post 详情请参阅http://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started.html#getting-started-new-post

If you are using GET then here are the details http://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started.html#getting-started-new-get 如果您使用的是GET,则以下是详细信息: http://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started.html#getting-started-new-get

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM