Yogesh Sharma
Yogesh Sharma

Reputation: 135

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.

Upvotes: 3

Views: 2198

Answers (1)

Ninad Gaikwad
Ninad Gaikwad

Reputation: 4500

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

Upvotes: 2

Related Questions