6

我正在尝试使用 ember-cli-deploy 和 ember-cli-deploy-cloudfront 将 ember 应用程序部署到 AWS CloudFront。

我在 AWS 中设置了我的存储桶和用户,为我的用户提供了 AmazonS3FullAccess 策略。

将我的.env.deploy.production文件设置为如下所示:

AWS_KEY=<my key>
AWS_SECRET=<my secret>
PRODUCTION_BUCKET=<app.<my domain>.com
PRODUCTION_REGION=us-east-1
PRODUCTION_DISTRIBUTION=<my cloudfront distribution id>

我的config/default.js样子是这样的:

/* jshint node: true */

module.exports = function(deployTarget) {
  var ENV = {
    build: {},
    pipeline: {
      activateOnDeploy: true
    },
    s3: {
      accessKeyId: process.env.AWS_KEY,
      secretAccessKey: process.env.AWS_SECRET,
      filePattern: "*"
    },
    cloudfront: {
      accessKeyId: process.env.AWS_KEY,
      secretAccessKey: process.env.AWS_SECRET
    }
  };

  if (deployTarget === 'staging') {
    ENV.build.environment = 'production';
    ENV.s3.bucket = process.env.STAGING_BUCKET;
    ENV.s3.region = process.env.STAGING_REGION;
    ENV.cloudfront.distribution = process.env.STAGING_DISTRIBUTION;
  }

  if (deployTarget === 'production') {
    ENV.build.environment = 'production';
    ENV.s3.bucket = process.env.PRODUCTION_BUCKET;
    ENV.s3.region = process.env.PRODUCTION_REGION;
    ENV.cloudfront.distribution = process.env.PRODUCTION_DISTRIBUTION;
  }

  return ENV;
};

我安装了ember-cli-deploy,ember-cli-deploy-cloudfrontember install ember-cli-deploy-aws-pack.

当我跑ember deploy production

我收到此错误:

AccessDenied: User: arn:aws:iam::299188948670:user/Flybrary is not authorized to perform: cloudfront:CreateInvalidation

我的理解是ember-cli-deploy-cloudfront为您处理创建失效,但是当我看到这个错误时,我进入 AWS IAM 控制台并自己创建了一个失效。当我尝试运行时,我仍然遇到同样的错误ember deploy production

4

1 回答 1

8

IAM 策略不允许限制对特定 CloudFront 分配的访问。解决方法是对资源使用通配符,而不是仅引用特定的 CloudFront 资源。将其添加到您的 IAM 策略将解决您遇到的问题。

以下是有效 IAM 策略中的示例:

{
  "Statement": [  
    {
      "Effect": "Allow",
      "Action": "s3:*",
      "Resource": "arn:aws:s3:::*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "cloudfront:CreateInvalidation",
        "cloudfront:GetInvalidation",
        "cloudfront:ListInvalidations"
      ],
      "Resource": "*"
    }
  ]
}

文件:

于 2016-08-02T20:51:07.557 回答