Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a python code placed in S3 using Lambda function

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.

like image 960
Yogesh Sharma Avatar asked Oct 26 '25 00:10

Yogesh Sharma


1 Answers

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

like image 132
Ninad Gaikwad Avatar answered Oct 27 '25 19:10

Ninad Gaikwad