I have a .py file with code in a AWS Cloud9 environment.
I want to run this code when a file is uploaded to a specific S3 Bucket.
But, it seems that I only can have triggers with AWS Lambda functions. I don't know how to add triggers to the AWS Cloud9 functions...
My simple code in the .py file in the Cloud9 environment is:
import boto3
import os
import sys
s3 = boto3.client('s3')
s3.download_file('our-awesome-first-test-bucket', 'test_text.txt', 'test_text_saved_to_env.txt')
with open('test_text_saved_to_env.txt', 'r') as f:
output = sum(map(int, f))
with open('output_to_awesome_bucket.txt', 'w') as outf:
outf.write(str(output))
s3.upload_file('output_to_awesome_bucket.txt', 'outputbucket-for-our-first-awesome-bucket', 'output_to_awesome_bucket.txt')
os.remove('test_text_saved_to_env.txt')
os.remove('output_to_awesome_bucket.txt')
How can I trigger this code to run when a file is uploaded to the S3 Bucket?