13

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).

sakhunzai
  • 13,900
  • 23
  • 98
  • 159

2 Answers2

30

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.

SarangArd
  • 1,115
  • 3
  • 12
  • 18
Dominic Nguyen
  • 753
  • 6
  • 11
2

This is based on NodeJS, but it should be the same for Python. The Constant under Input is a simple JSON encoded object, which can then be accessed using the event variable.

Input

{ "config": "uk" }

Lambda

console.log(event.config)

Found this entry as one of the top Google results, so hopefully this will help someone else.

knrdk
  • 536
  • 5
  • 13