简体   繁体   English

如何配置 AWS Amplify 的 Storage.put 以使用传输加速的 s3 存储桶域?

[英]How to configure AWS Amplify's Storage.put to use a transfer accelerated s3 bucket domain?

I've enabled S3 Transfer Acceleration using Cloudformation .我已经使用Cloudformation启用了S3 传输加速

The documentation says that after enabling it, developers need to point their clients to use the new accelerated domain name.文档说,启用后,开发人员需要让他们的客户使用新的加速域名。

Eg from mybucket.s3.us-east-1.amazonaws.com to bucketname.s3-accelerate.amazonaws.com .例如从mybucket.s3.us-east-1.amazonaws.combucketname.s3-accelerate.amazonaws.com

However, AWS Amplify's Storage.put method is using the bucket name defined during configuration like so:但是,AWS Amplify 的 Storage.put 方法使用的是在配置期间定义的存储桶名称,如下所示:

Amplify.configure({
  Storage: {
    AWSS3: {
      bucket: AWS_BUCKET_NAME,
      region: AWS_REGION
    }
  }
})

Since there is no domain name here, but only a bucket name, how does one set it to access the accelerated endpoint instead?既然这里没有域名,只有一个bucket名,那怎么设置成访问加速的endpoint呢?

It's seems to me that Amplify Storage doesn't support this configuration out of the box, so if you want to use Transfer Acceleration you will need to use the standard S3 client for javascript like so:在我看来,Amplify Storage 不支持这种开箱即用的配置,所以如果你想使用 Transfer Acceleration,你需要使用 javascript 的标准 S3 客户端,如下所示:

// obtain credentials from cognito to make uploads to s3...
let albumBucketName = "BUCKET_NAME";
let bucketRegion = "REGION";
let IdentityPoolId = "IDENTITY_POOL_ID";

AWS.config.update({
region: bucketRegion,
credentials: new AWS.CognitoIdentityCredentials({
    IdentityPoolId: IdentityPoolId
})
});

// configure the S3 client to use accelerate - note useAccelerateEndpoint flag
const options = {
    signatureVersion: 'v4',
    region: bucketRegion, // same as your bucket
    endpoint: new AWS.Endpoint('your-bucket-name.s3-accelerate.amazonaws.com'),    
    useAccelerateEndpoint: true,  
};
const s3 = new AWS.S3(options);

// then use the client...
// ...

Reference for the class AWS.S3:https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html class AWS.S3 的参考:https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html

I also was struggling with this and stumbled on now to enable this with Storage.put:我也在为此苦苦挣扎,现在偶然发现使用 Storage.put 启用它:

  1. Specify your normal bucket name, as you normally would像往常一样指定您的正常存储桶名称
  2. In the options object for Storage.put, set useAccelerateEndpoint: true (which I took from the above answer)在 Storage.put 的选项 object 中,设置 useAccelerateEndpoint: true (我从上面的答案中得到)

If you do a test, and look at the network console for the Chrome Developer Tools, you will see that Amplify specifies the correct path for the accelerated endpoint.如果您进行测试,并查看 Chrome 开发人员工具的网络控制台,您将看到 Amplify 为加速端点指定了正确的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Amplify 的 Storage.put 将多个文件添加到 S3 - Adding multiple files to S3 with Amplify's Storage.put AWS Amplify 存储权限、S3 存储桶 - AWS Amplify Storage permissions, S3 bucket 如何使用Powershell访问Transfer Accelerated S3存储桶 - How to access Transfer Accelerated S3 bucket using Powershell 用于 S3 存储桶的 AWS 上的 GoDaddy 域,如何? - GoDaddy domain on AWS for S3 bucket, HOW? 使用PHP将对象上传到传输加速S3存储桶 - Uploading object into transfer accelerated S3 bucket using PHP 在Godaddy上将域配置到Amazon S3存储桶 - Configure domain on Godaddy to Amazon S3 bucket 如何配置aws s3存储桶接受Heroku上的签名网址? - How to configure aws s3 bucket to accept signed urls on Heroku? 如何将域定向到 aws s3 存储桶上的子文件夹? - How do I direct a domain to a subfolder on an aws s3 bucket? 如何配置 s3 存储桶以允许 aws 应用程序负载均衡器(不是类)使用它? 当前抛出“拒绝访问” - how to configure s3 bucket to allow aws application load balancer (not class) use it? currently throws' access denied' aws-amplify S3 存储上传文件,但尽管有明确的公共访问配置,但仍将它们设为“私有” - aws-amplify S3 Storage uploads files but put them as "private" despite of explicit public access configuration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM