bamishr
bamishr

Reputation: 429

Does AWS Lambda have the capability to connect to EC2 and S3 in a single lambda function?

I am trying to copy the files uploaded to S3 bucket to an EC2. Now we have multiple files will be uploaded everyday to S3 bucket. I want to use a lambda function so that if a file is uploaded to S3 bucket then AWS Lambda should capture the event and copy the respective file to EC2. How can we achieve this??

Does AWS lambda have the capability to connect with EC2 and S3 in a single lambda function??

Upvotes: 0

Views: 520

Answers (2)

Levi
Levi

Reputation: 99

You can use AWS SSM, whenever there are files uploaded to s3, then lambda will issue this command inside the EC2

$ aws s3 cp <source-bucket> <destination-ec2-path>

note that, the EC2 need to install SSM Agent, hope this will help

Upvotes: 0

LostJon
LostJon

Reputation: 2387

Lambda can connect to S3, so long as the IAM Permissions are correct (s3:PutObject or s3:GetObject). As for EC2, I would recommend mounting an EFS to Lambda, and using that same EFS with EC2. You really do not want to go down a path of writing to EBS (ie the storage volume typically associated with EC2) because you will have a potential to fill the storage, and cause outage with that EC2.

If you are already uploading to S3, I don't really understand why your architecture would require you copy it to EC2, rather than permitting the EC2 access to S3 via an Instance profile (but hey, I'm not your architect).

Upvotes: 4

Related Questions