It's being a while I'm struggling with this situation:
- I have a local application in PHP (WordPress)
- When I commit my changes I send the changed files automatically to S3 via Git Hooks
- S3 Bucket receives these changed files
- Right after this, I send a notification to a lambda function when the file is included/deleted
- In the lambda function, using javascript for instance, I have identified the bucket and file names (So far so good).
The question is: How can I copy this file from the Bucket to the EC2 to complete my automation ?
What I have tried so far:
A) Manually speaking I can do something like this inside my ec2 instance, that works perfectly:
aws s3 sync s3://my-bucket "\var\www\html*" --exclude "wp-config.php"
B) Also I have executed one similar command on "SSM Run Command" like this that also works perfectly:
wget https://my-bucket.s3.amazonaws.com/file.txt
C) Trying to create a very simple SSM document that execute a simple random bash script like I have done in the previous attempt, trying to create the document - create command or session - session type and trying some versions of what you can see in this example (with/whitout quotations...):
---
schemaVersion: "2.2"
description: "Command Document Example JSON Template"
parameters:
Message:
type: "String"
description: "Example"
default: "Hello World"
mainSteps:
- action: "aws:runPowerShellScript"
name: "example"
inputs:
runCommand:
- cd /var/www/html
- wget https://my-bucket.s3.amazonaws.com/file.txt
With this error: failed to run commands: fork/exec /usr/bin/pwsh: no such file or directory (even trying with and without quotes)
If someone have some idea, maybe a code somewhere to help me automate the copy of a single file from S3 to EC2 this would be very apreciated !!!
Thank You guys in advance ! :)
AWS-RunShellScriptdocument. - Marcin