1

So this is my .travis.yml:

language: python
python:
  - "3.5"
cache: pip
install:
  - pip install awscli

script:
  - echo 'test'

deploy:
  provider: s3
  access_key_id: $AWS_ACCESS_ID
  secret_access_key: $AWS_SECRET_ID
  bucket: "xxxxx.com"
  local_dir: build
  skip_cleanup: true
  cache_control: "max-age=21600"
  on:
    branch: master

after_deploy:
  - aws configure set preview.cloudfront true
  - aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*"

It is just a html page without node or other framework. I want to push to AWS S3 bucket, and create an invalidation for this bucket's cloudfront.

The problem is, it can upload into AWS S3 bucket successfully, and can't run cloudfront to create invalidation.

I got this error message from Travis.

> Deploying application
> uploading "index.html" with {:content_type=>"text/html", :cache_control=>"max-age=21600"}

>$ aws configure set preview.cloudfront true
>$ aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*"

Unable to locate credentials. You can configure credentials by running "aws configure".
Done.

Any thoughts on that?

JD D
  • 7,398
  • 2
  • 34
  • 53
Wei Xia
  • 504
  • 2
  • 9
  • 24

1 Answers1

2

I believe this is because your S3 upload you are providing the access keys but those are specific to that operation. You need to setup your credentials so they can be used by the AWS CLI commands in your after_deploy. Try this in your after_deploy:

after_deploy:
  - aws configure set aws_access_key_id $AWS_ACCESS_ID
  - aws configure set aws_secret_access_key $AWS_SECRET_ID
  - aws configure set preview.cloudfront true
  - aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*"
JD D
  • 7,398
  • 2
  • 34
  • 53
  • [here is also a related question with alternative approaches](https://stackoverflow.com/questions/37267916/how-to-run-aws-configure-in-a-travis-deploy-script) – JD D Jun 07 '19 at 01:11
  • Thanks for your solution. It's resolved. Very helpful! – Wei Xia Jun 07 '19 at 01:48