aws python lambda_如何使用Python将参数传递给AWS Lambda函数 - python

我已经用Python编写了一个AWS Lambda函数,该函数可筛选实例并根据其标记方式打开或关闭它们。这将向您显示一个工作功能,以及使它工作所需的设置。如果您有任何疑问,请在评论中发布。

到目前为止,这是我的Lambda函数:

import boto3

def lambda_handler(event, context):

startStop = event['startStop']

vertical = event['vertical']

isRunning = ''

if(startStop == 'start'):

isRunning = 'stopped'

elif (startStop == 'stop'):

isRunning = 'running'

ec2 = boto3.resource('ec2')

filters = [

{

'Name': 'instance-state-name',

'Values': [isRunning]

},

{

'Name': 'tag:Vertical',

'Values': [vertical]

}

]

instances = ec2.instances.filter(Filters=filters)

runningInstances = [instance.id for instance in instances]

if len(runningInstances) > 0:

if(startStop == 'start'):

shuttingDown = ec2.instances.filter(InstanceIds=runningInstances).start()

elif (startStop == 'stop'):

shuttingDown = ec2.instances.filter(InstanceIds=runningInstances).stop()

供参考,这是我的映射模板:

{

"startStop":"$input.params('startStop')",

"vertical":"$input.params('vertical')"

}

这就是我在URL中传递参数的方式:

https://awslambdaapiurl.../prod/-params?startStop=start&vertical=TEST

参考方案

在映射模板中传递参数值:

{

"startStop":"$input.params('startStop')",

"vertical":"$input.params('vertical')"

}

通过event对象读取参数值:

startStop = event['startStop']

vertical = event['vertical']

在返回'Response'(Python)中传递多个参数 - python

我在Angular工作,正在使用Http请求和响应。是否可以在“响应”中发送多个参数。角度文件:this.http.get("api/agent/applicationaware").subscribe((data:any)... python文件:def get(request): ... return Response(seriali…Python exchangelib在子文件夹中读取邮件 - python

我想从Outlook邮箱的子文件夹中读取邮件。Inbox ├──myfolder 我可以使用account.inbox.all()阅读收件箱,但我想阅读myfolder中的邮件我尝试了此页面folder部分中的内容,但无法正确完成https://pypi.python.org/pypi/exchangelib/ 参考方案 您需要首先掌握Folder的myfo…R'relaimpo'软件包的Python端口 - python

我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。Python ThreadPoolExecutor抑制异常 - python

from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED def div_zero(x): print('In div_zero') return x / 0 with ThreadPoolExecutor(max_workers=4) as execut…如何用'-'解析字符串到节点js本地脚本? - python

我正在使用本地节点js脚本来处理字符串。我陷入了将'-'字符串解析为本地节点js脚本的问题。render.js:#! /usr/bin/env -S node -r esm let argv = require('yargs') .usage('$0 [string]') .argv; console.log(argv…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值