I am trying to sync a S3 bucket which takes close to 3 hours to completely sync.
sync-bucket.sh:
nohup aws s3 sync "$source_bucket/$folder/" "s3://$destination_bucket/" \
--profile abc --acl bucket-owner-full-control --sse "aws:kms" \
--sse-kms-key-id "$KEY_ARN" > /var/log/$folder.log 2>&1 &
echo "Successfully triggered the sync job"
I was hoping to trigger the sync job using AWS SSM send command something like below:
trigger.sh:
COMMAND=$(aws ssm send-command --document-name "AWS-RunShellScript" \
--targets "Key=instanceids,Values=${RECOVERY}" \
--parameters '{"executionTimeout":["10800"],"commands":["/opt/scripts/sync-bucket.sh"]}' \
--output-s3-bucket-name "some-bucket" \
--timeout-seconds 10800 \
| jq -r '.Command.CommandId')
My observation is that SSM waits for this background job to finish before marking the execution as 'Success'. Is there a way we could perhaps just trigger the background job and make SSM finish the execution without having to wait for background job to finish?
Or is there a better way of doing this? I am basically trying to automate the process here and happy to let the job running in background on demand without having to login to instance and run command manually.
Thanks for your time.