amazon-web-servicesamazon-s3github-actionscontentful

AWS Sync S3 on Github Workflow - Only overwrite one folder


At the moment I have a Github workflow that when it runs it syncs the entire project to my AWS S3 bucket, deleting the previous version.

I want to change this now to only overwrite one folder in the project, as I have multiple sites in one Contentful space now and don't want it to rebuild the entire site, just the one.

At the moment the AWS script is:

name: Copy files to the s3 website content bucket
if: ${{ success() }}
run: aws s3 sync dist s3://${{env.AWS_S3_BUCKET}} --delete --acl public-read

If I want to change it to only upload one folder and remove the old version, would this be correct:

 name: Copy files to the s3 website content bucket
 if: ${{ success() }}
 run: aws s3 sync /pages/first-website s3://${{env.AWS_S3_BUCKET}}/pages/first-website --include "/pages/first-website" --exclude "*" --delete --acl public-read

Solution

  • You would have to use:

    aws s3 sync dist s3://${{env.AWS_S3_BUCKET}} --exclude "*" --include "/pages/first-website/*" --delete --acl public-read
    

    note that --exclude must come before --include, since:

    When there are multiple filters, the rule is the filters that appear later in the command take precedence over filters that appear earlier in the command.

    from https://docs.aws.amazon.com/cli/latest/reference/s3/index.html#use-of-exclude-and-include-filters