Amazon S3 and Cloudfront cache, how to clear cache or synchronize their cache

后端 未结 9 990
死守一世寂寞
死守一世寂寞 2021-01-30 05:59

I have a cron job that runs every 10 minutes and updates the content-type and x-amz-meta. But since yesterday it seems like after the cron job run, Amazon is not picking up the

9条回答
  •  囚心锁ツ
    2021-01-30 06:55

    As to the actual code

    get your CloudFront distribution id

    aws cloudfront list-distributions

    Invalidate all files in the distribution, so CloudFront fetches fresh ones

    aws cloudfront create-invalidation --distribution-id=S11A16G5KZMEQD --paths /

    My actual full release script is

    #!/usr/bin/env bash
    
    BUCKET=mysite.com
    SOURCE_DIR=dist/
    
    export AWS_ACCESS_KEY_ID=xxxxxxxxxxx
    export AWS_SECRET_ACCESS_KEY=xxxxxxxxx
    export AWS_DEFAULT_REGION=eu-west-1
    
    
    echo "Building production"
    if npm run build:prod ; then
       echo "Build Successful"
    else
      echo "exiting.."
      exit 1
    fi
    
    
    echo "Removing all files on bucket"
    aws s3 rm s3://${BUCKET} --recursive
    
    
    echo "Attempting to upload site .."
    echo "Command:  aws s3  sync $SOURCE_DIR s3://$BUCKET/"
    aws s3  sync ${SOURCE_DIR} s3://${BUCKET}/
    echo "S3 Upload complete"
    
    echo "Invalidating cloudfrond distribution to get fresh cache"
    aws cloudfront create-invalidation --distribution-id=S11A16G5KZMEQD --paths / --profile=myawsprofile
    
    echo "Deployment complete"  
    

    References

    http://docs.aws.amazon.com/cli/latest/reference/cloudfront/get-invalidation.html

    http://docs.aws.amazon.com/cli/latest/reference/cloudfront/create-invalidation.html

提交回复
热议问题