user6136315
user6136315

Reputation: 705

How to update S3 bucket with expire date using AWS CLI

I would like to update the S3 bucket with the new content(create a folder within a bucket). What is the --expires date format. I didn't find any examples using AWS CLI on google. Can someone please help me on this thing?

Something like this:

aws s3 sync $backup_home s3://backup/$app-backup/$app-$DATE --expires '$DATE'

Upvotes: 13

Views: 8455

Answers (1)

Anthony Neace
Anthony Neace

Reputation: 26021

aws s3 sync expects a GMT ISO 8601 datetime string as the format for the --expires option. Something like this:

aws s3 sync --expires '2016-06-14T00:00:00Z' $backup_home s3://backup/$app-backup/$app-$DATE

The ISO 8601 standard allow simple dates, so if the exact time of day your object expires doesn't matter and you want to use a relative time in the future you can use this bash shell syntax:

  --expires "$(date -I -d '30 days')"

The -I flag enables ISO 8601 date formatting and the -d flag tells the date command to print the date described by the following string.

Upvotes: 23

Related Questions