为什么要让AccessDenied将Gatsby部署到S3?

时间:2019-02-15 21:00:21

标签: amazon-s3 gatsby

我正在按照this指南使用Gatsby部署到S3存储桶。

如果我运行using Microsoft.AspNet.SignalR.Client; using System; namespace Acme.Core.SignalR { public class SignalRPipe : IObservable<PipeCommand> { readonly IHubProxy _MyHub; private SignalRPipe() : base() { } private SignalRPipe( IHubProxy hub ) : this() { _MyHub = hub; } public IDisposable Subscribe( IObserver<PipeCommand> observer ) { var rtrn = _MyHub.On<PipeCommand>( "OnPipeCommand" , pc => observer.OnNext( pc ) ); return rtrn; } } }

我得到了我上传的单个文件:aws s3 ls mybucketname.com

但是,如果我运行2019-02-15 15:53:58 477 favicon-16x16.png

我收到此错误:

npm run deploy

这是我的> gatsby-plugin-s3 deploy ✖ Failed. AccessDenied: Access Denied 中的相关代码:

gatsby-config.js

这是我在AWS中创建的用户所附的IAM策略:

plugins: [
{
     resolve: `gatsby-plugin-s3`,
     options: {
         bucketName: 'mybucketname.com'
     },
 },

还有其他可以确定该错误来自何处的东西吗?

3 个答案:

答案 0 :(得分:1)

尝试在gatsby-plugin-s3选项中设置acl: null

plugins: [
{
  resolve: `gatsby-plugin-s3`,
  options: {
    bucketName: 'mybucketname.com',
    acl: null
  }
}

答案 1 :(得分:0)

我遇到了同样的问题,这是由于我尚未配置用于访问网站的S3存储桶(托管网站所必需的)而导致的: https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteAccessPermissionsReqd.html

从技术上讲, gatsby-plugin-s3 不需要它,因为上传工作是通过使用提供的IAM凭证通过AWSCLI完成的;但是我想只是在开始上传之前列出存储区,或者是打算公开执行其他操作,而不是使用IAM凭据来执行。

答案 2 :(得分:0)

如果您使用带有 S3 的 CloudFront,问题之一可能是重写默认索引文件。要让路由在没有 void PopBack(); // Deletes the element at the end of the vector. bool Empty() const; // Tests if the vector container is empty. int Size() const; // Returns the number of elements in the vector. int Capacity() const; // Returns the number of elements that the vector could contain without allocating more storage. bool operator==(const Vector& right_hand_side) const; bool operator!=(const Vector& right_hand_side) const; friend std::ostream& operator <<(std::ostream& ostr, const Vector& rhs); Vector& operator=(const Vector& rhs); int& operator[](int index); int& At(int index); // Returns a reference to the element at a specified location in the vector. int& Front(); // Returns a reference to the first element in a vector. int& Back(); // Returns a reference to the last element of the vector. void Insert(int index, int value); // Inserts an element or many elements into the vector at a specified position. void Erase(int index); // Removes an element or a range of elements in a vector from specified positions. void Clear(); // Erases the elements of the vector. private: int size; int capacity; int* array; char* char_array; }; 的情况下工作,您必须在 CloudFront 上重写请求。你可以用 lambda 函数做到这一点。

这是一个旧文档 https://aws.amazon.com/blogs/compute/implementing-default-directory-indexes-in-amazon-s3-backed-amazon-cloudfront-origins-using-lambdaedge/

新的工作代码在这里https://github.com/aws-samples/amazon-cloudfront-functions/blob/main/url-rewrite-single-page-apps/index.js