S3 list result to file or variable

Hi. Im trying to automate our restore machine testing.
At one point i need to connect to amason S3 and download the latest data from a bucket.

s3://bucet.name/application_name/DATE/version/files1-3

What i have tried thus far:

  • name: List s3 objects
    aws_s3:
    bucket: “bucket.name”
    prefix: “/application_name/”
    dest: /home/user/tmp-file
    mode: list
    max_keys: 5
    register: s3objects

become: yes
become_user: user

  • name: show list?
    debug:
    msg: “heres the list: {{ s3objects.s3_keys }}”

  • name: write to file
    copy:
    content: “{{ s3objects }}”
    dest: /home/user/tmp-file
    with_items: s3objects.s3_keys
    become: yes
    become_user: user

The tmp file has this info:
“{“msg”: “LIST operation complete”, “failed”: false, “changed”: false, “s3_keys”: }”

Im very new to ansible, what i would ultimately want is to get this:
aws s3 ls s3://bucet.name/application_name/ | tail -5

hmm i see that i have one thing wrong.

prefix is not what i thought it was. If i remove it i get the list for all the applications.

ANd if i enter prefix without / \ then i get the correct data.
max_keys has no effect tho.

kolmapäev, 7. november 2018 15:57.20 UTC+2 kirjutas ton...@gmail.com:

That must be irritating, since every example has leading slashes on the prefix!

Regards, K.