4

I have a python code placed in S3. That python code would be reading an excel file as source file placed in S3 and will do some transformations.

I have created a Lambda function which will get triggered once there will be a PUT event on the S3(whenever source gets placed to the S3 folder).

Requirement is to run that python code using the same Lambda function or to have the python code configured within the same Lambda function.

Thanks in advance.

1 Answer 1

2

You can download the python code to /tmp/ temporary storage in lambda. Then you can import the file inside your code using the import statement. Make sure your import statement gets executed after you have downloaded the file to tmp.

You can also have a look here to see other methods to run new script from within script.

EDIT: Here's how you can download to /tmp/

import boto3

s3 = boto3.client('s3')
s3.download_file('bucket_name','filename.py','/tmp/filename.py')

Make sure your lambda role has permission to access s3

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

4 Comments

Thanks.. can you please help me with a pseudo code for storing the code in temp location. I am pretty new to these things.
What programming language are you using?
Python language
No problem. Please mark as correct and upvote if it solves your problem.

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.