The update helped me find a solution. Thank you This is cleaner than the answer suggested by hussfelt.
Using awscli
Since using the specified command required some research, I will explain how I had to change my .travis.yml for everyone who found this post.
before_deploy: pip install
Install awscli first to enable synchronization with the S3 bucket. We cannot use sudo to work with the container architecture of Travis, so install --user in the home directory. On Linux, which is the default OS on Travis, binaries installed with this option are located in ~/.local/bin/ -
deploy: provider: script
Then use the script provider to run the user command as a deployment method.
script: ~/.local/bin/aws s3 sync dist s3://example.com --region=eu-central-1 --delete
This line loaded your files. aws s3 sync used to synchronize files between the local machine and buckets. Full documentation is available here .
In my dist example, there is an assembly folder that we want to upload to S3. Your build system might call it build or something else. "example.com" is the name of your bucket. An area argument is required to uniquely identify your bucket.
A really interesting bit in this command is the --delete switch, which is the solution to our problem. When installed, aws will delete all files found in your bucket, but not in your build directory.
skip_cleanup: true on: branch: master
skip_cleanup must be installed or none of your files will be downloaded. Personally, I like that the deployment of Travis is only fixed to master , but any configuration is possible here. See docs for more details.
Environment
We need to provide aws our AWS credentials to allow any interaction. The environment variables used by aws are AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY . hussfelt writes how to provide them in his answer. This process is also described in the Travis documentation: encryption and AWS Features .
Complete solution
# Deploy using awscli to enable pruning of removed files before_deploy: pip install --user awscli deploy: provider: script script: ~/.local/bin/aws s3 sync dist s3://example.com --region=eu-central-1 --delete skip_cleanup: true on: branch: master