1

I am currently working on my lambda function (Python) which is triggered using cron expression in CloudWatch Events.

I want to pass some data to the function (ideally in the form of a dictionary) and those values can then be used inside the lambda_handler to do calculations based on the custom input parameters.

I did some research and there are methods using the API gateway but I do not have the liberty to use the API gateway.

Is there a way I can pass custom input parameters to my function? I am new to AWS Lambda so this question might seem silly to veterans. Thanks in advance

Edit 1: After trying out the solution provided in the first answer I faced come other issues.

Input Config: enter image description here

Here's the snippet from the lambda function where im trying to push input data into Postgres database:

s={'upload_date': today,'data':'Test Data','Remark':event["data"]}
log_success = pd.DataFrame(data = [s])
log_success.to_sql(log_table, con, schema = "some_existing_schema", if_exists = "append",index = False, method = "multi")

ERROR:

[ERROR] KeyError: 'data' Traceback (most recent call last):   File "/var/task/test.py", line 38, in lambda_handler     s={'upload_date': today,''data':'Test Data','Remark':event["data"]}

1
  • Can you provide some code example of what you already did? Commented Jun 4, 2020 at 12:44

1 Answer 1

1

When you configure your lambda as target in your CW Event rule, you can Configure inputs which will be passed to your function.

For example, you can pass a constant string or json:

enter image description here

Using Input transformer you can modify regular CW event data that is normally passed to your function, and add extra information to it.

But you have to remember that these are fixed inputs. For every invocation of your function by cron from CW Events rule, the input parameters will be same.

If you want to trigger your lambda function yourself and pass custom arguments each time, then you either have to use aws api (e.g. aws lambda invoke AWS CLI) or do it through a API gateway. The first method will require AWS credentials to invoke the function, while the second one can be made public and work without AWS credentials.

Sign up to request clarification or add additional context in comments.

5 Comments

Hi, Thanks for answering. Elaborate more on the first method you suggested (aws lambda invoke AWS-CLI) or share some resources? I feel there is not enough about this in the AWS documentation
@umangMistryBO The direct invokation of the function is documented here. For that to work you would have to install aws cli and setup your aws credentials to be used by the cli.
Is there a way to schedule the invoking? Cause upon observing the documentation you shared there is no schedule-expression mentioned.
Hi I tried out the method of fixed input with the scheduled Rule in AWS CW (Image attached above). I tried to access it in the function and Im getting an error. Could you point out where I'm missing out? Thanks
I have added a new question for the new error. Would love to get some help. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.