Copy file from S3 to Remote Host

Hi Everyone,

I want to copy a file from S3 to an EC2 host. How can I achieve that? Aws_s3 module has destination but I am not sure how can I use that to provide a remote server location?

Here is working example:

  • name: Download the latest version of app from S3 bucket
    aws_s3:
    aws_access_key: “{{ AWS_S3_ACCESS_KEY }}” # take from env or using profile
    aws_secret_key: “{{ AWS_S3_SECRET_KEY }}”
    bucket: BUCKET-FULL-NAME
    object: “/directory-inside-bucket/file-that-you-want-to-download”
    mode: get
    dest: “/tmp/file-name” #will download and store in /tmp with your provided filename

Don’t forget to install boto3 on remote host otherwise it will fail. Le me know if you need any help