How to pass and retrieve constant json data to lambda function

sakhunzai picture sakhunzai · Nov 18, 2016 · Viewed 11.3k times · Source

enter image description here

I have lambda function defined sth like :

def lambda_handler(event, context):

   #get constant json argument passed from cloudwatch event rule

   ...

What is the way to get the values defined in Target/Configure Input /Constant(Json text).

Answer

Dominic Nguyen picture Dominic Nguyen · Apr 7, 2017

As I read in AWS documents, json passed to python as dict type. And then I simply call the value like this:

passed json:

{"type": "daily", "retention": 7}

Then in your handler:

def lambda_handler(event, context):
    type = event["type"]
    rententionDay = event["retention"]
    ...

Use this I was able to make an automation snapshot for all ebs volumes. Hope it help.