Question

I am trying to use s3cmd tool to invalidate my files, it seems s3cmd automatically choose a distribution for me, but I have more distributions from the same bucket, how can I choose distribution to invalidate ?

I have tried this :

s3cmd sync —cf-invalidate myfile cf://XXXXXXXXXX/mypath but it does not work. I get this: Invalid source/destination”

any idea?

thanks!

Était-ce utile?

La solution

I believe you'd be looking to force an invalidation via the origin (i.e. your S3 bucket or similar) like so:

s3cmd --cf-invalidate _site/ s3://example-origin.com/

Autres conseils

Here is my final conclusion:
after many many tries , the solution is very restrict.

  1. follow this format:

s3cmd sync --cf-invalidate --acl-public --preserve --recursive ./[local_folder] s3://[my_bucket]/[remote_folder]/

  1. when I run this command , the actual folder should be in command running folder

  2. local file should have ./

  3. remote folder should be end by /

I could not make s3cmd's invalidation work, so I used s3cmd to update the file and cloudfront-invalidator to do the invalidation. The script reads the aws authentication used by s3cmd for cloudfront-invalidator.

#!/bin/bash

if [ -z "$(which s3cmd)" ]; then
  echo "s3cmd is not installed or is not on the PATH"
  exit -1
fi

if [ -z "$(which cloudfront-invalidator)" ]; then
  echo "cloudfront-invalidator is not installed or is not on the PATH"
  echo "See https://github.com/reidiculous/cloudfront-invalidator"
  echo "TL;DR: sudo gem install cloudfront-invalidator"
  exit -1
fi

function awsKeyId {
  awk -F '=' '{if (! ($0 ~ /^;/) && $0 ~ /aws_access_key_id/) print $2}' ~/.aws/config | tr -d ' '
}

function awsSecret {
  awk -F '=' '{if (! ($0 ~ /^;/) && $0 ~ /aws_secret_access_key/) print $2}' ~/.aws/config | tr -d ' '
}

export file="stylesheets/main.css"
export distributionId=blahblah
export bucket=www.blahblah

s3cmd -P -m 'text/css' put public/$file s3://$bucket/$f
cloudfront-invalidator invalidate `awsKeyId` `awsSecret` $distributionId $file
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top