简体   繁体   中英

AWS Lambda function + Cloudwatch, how to pass the right parameters to a timed execution

I have had success building functions on AWS Lambda and passing parameters to the function to test and execute as I see fit. However, I am finding it hard to locate where to configure what needs to be passed to my functions on a timed event using Cloudwatch. I see the easiest way was to have no event or context (event=None and context=None) but as I have become more sophisticated I have some testing parameters now built in that require me to simply pass the following:

{
   "testing" : "True"
}

Again, I already have the function up and running but now it is built to accept this when it is needing to actually perform it's job for the management team:

{
   "testing" : "False"
}

I do see configs for Event Bus being set to default but I cannot locate what CloudWatch was actually doing in the first place so I can modify it (hopefully) to pass the False statement to my function.

All my functions are in python 3.7 and if more info is needed, let me know. I have reviewed questions on here regarding similar issues, such as this but cannot locate these libraries and I believe I would need to configure something custom in the future as well. Thanks

I do something similar to what you're after - I trigger a Lambda to create a snapshot of an EBS volume. I have used the console to configure my Cloudwatch events. In Events->Rules->Actions (upper right hand corner)->Edit, I have the following:

在此处输入图片说明

My constant JSON looks like:

{
"volumeId": "vol-0c4079999999999",
 "description":"Jenkins Snapshot",
 "name": "jenkins-snapshot"
}

And I parse this information out to use in my Lambda. I have multiple events that use this same Lambda and they each just have a different constant JSON in them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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