How to download files from S3 in SaltStack
How to download files stored in S3 and manage it in SaltStack
To manage a file using salt stack configuration we can use file.managed state. This state downloads the file from salt master server or HTTP / FTP server or it can point to local system file as well.
It also supports downloading files from S3 URL’s
There are two things which needs to be done to download files from S3
- Give S3 URL in source parameter of file.managed state in your salt states file
- Configure required AWS keys in minion config so that SaltStack can use those keys to access files store in AWS S3 bucket and download it.
In your state file you have to give S3 URL in
source parameter of
file.managed state as below.
<bucketname> with your the actual bucketname and
<path-to-file> with the path of the file under bucket for example
Let say your bucket name is
myBucket then your final URL will be
download_file_from_s3: file.managed: - name: /opt/file_from_s3.jar - source: s3://<bucketname>.s3.amazonaws.com/<path-to-file> - user: root - group: root - mode: 755
You have to add below details in your minion config file, change
key as per your account and location should match the location where you have created your AWS S3 bucket.
Refer salt.module.s3 for more available options.
# AWS access keys to download files from S3 bucket s3.keyid: XXXXXXXXXXXXXXXXXXXXXX s3.key: XXXXXXXXXXXXXXXXXXX s3.location: us-east-1