使用 Travis 时,为什么我无法在 after_deploy 中找到凭据

While using Travis, why do I get unable to locate credentials in after_deploy

所以这是我的 .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 "/*"

它只是一个 html 页面,没有节点或其他框架。我想推送到 AWS S3 存储桶,并为此存储桶的云端创建一个失效。

问题是,它可以成功上传到 AWS S3 存储桶,但不能 运行 cloudfront 创建失效。

我从 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.

对此有什么想法吗?

我相信这是因为您的 S3 上传提供了访问密钥,但这些是特定于该操作的。您需要设置您的凭据,以便您的 after_deploy 中的 AWS CLI 命令可以使用它们。在您的 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 "/*"