简体   繁体   中英

Copy files from S3 bucket to EC2 Windows Instance using Lambda

I have uploaded design files (like images/css/js) to an S3 bucket and now I need to copy such files from the S3 bucket to an EC2 Windows instance whenever they are uploaded to/deleted from the bucket. I have created a Lambda function with a Powershell script but I don't see any way to access the EC2 instance and copy the files there. I tried the following script but I am seeing an error like Cannot find drive. A drive with the name 'C' does not exist Cannot find drive. A drive with the name 'C' does not exist

Start-EC2Instance -InstanceIds i-********
foreach ($i in Get-ChildItem -Path "C:\Windows")
{
Write-Host $i.FullName  

}

Can someone please help on this.

I use below pattern for a similar use case. In my case I want to run a powershell script on a newly created EC2 instance.

Ec2 instance (Windows) created -> CloudWatch event detects it -> Triggers Lambda Function -> Lambda Function runs an SSM document (it could very well be just SSM run commands like Ketanbhut suggested) -> SSM document runs the powershell script on the EC2 instance

In your case: Upload file to S3 -> S3 event notification (you need to configure this) triggers Lambda function -> Lambda Function runs an SSM document -> SSM document runs the powershell script on the EC2 instance

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM