简体   繁体   English

Rails 4 + Amazon S3:授予对Rails API的访问权限

[英]Rails 4 + Amazon S3: Grant access to Rails API

I have a Rails API and would like to enable access to my Amazon S3 Bucket but when my API attempts to access a URL that points to an object in my bucket, it receives a 403 Forbidden response. 我有Rails API,想启用对Amazon S3存储桶的访问,但是当我的API尝试访问指向存储桶中的对象的URL时,它将收到403 Forbidden响应。

I do not want to make the objects public, but would like to allow my API access. 我不想公开对象,但想允许我的API访问。 I've tried to generate a bucket policy but have had no luck. 我尝试生成存储桶策略,但是没有运气。

If anyone has experience with this, I would appreciate it. 如果有人对此有经验,我将不胜感激。

You need to create an IAM Policy that enables a set of credentials to access objects inside the S3 Bucket. 您需要创建一个IAM策略,以启用一组凭据来访问S3存储桶中的对象。 If you're not running your Rails application inside AWS, create a User that has this policy attached to it, with access credentials. 如果您不在AWS内部运行Rails应用程序,请创建一个附加了此策略并带有访问凭据的用户。 Otherwise, if you're running on AWS, you can attach an IAM policy to a Role, which is attached to an EC2 Instance, etc. 否则,如果您在AWS上运行,则可以将IAM策略附加到角色,该角色附加到EC2实例等。

See: https://aws.amazon.com/blogs/security/writing-iam-policies-how-to-grant-access-to-an-amazon-s3-bucket/ 参见: https : //aws.amazon.com/blogs/security/writing-iam-policies-how-to-grant-access-to-an-amazon-s3-bucket/

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM