AWS S3 Bucket Access from EC2

后端 未结 3 1104
情深已故
情深已故 2020-12-01 11:25

I need to fire up an S3 bucket so my EC2 instances have access to store image files to it. The EC2 instances need read/write permissions. I do not want to make the S3 bucket

相关标签:
3条回答
  • 2020-12-01 11:46

    This can be done very simply. Follow the following steps:

    • Open the AWS EC2 on console.
    • Select the instance and navigate to actions.
    • Select instances settings and select Attach/Replace IAM Role
    • Create a new role and attach S3FullAccess policy to that role.

    When this is done, connect to the AWS instance and the rest will be done via the following CLI commands:

    • aws s3 cp filelocation/filename s3://bucketname

    Please note... the file location refers to the local address. And the bucketname is the name of your bucket. Also note: This is possible if your instance and S3 bucket are in the same account. Cheers.

    0 讨论(0)
  • 2020-12-01 11:52

    You do not need to make the bucket public readable, nor the files public readable. The bucket and it's contents can be kept private.

    Don't restrict access to the bucket based on IP address, instead restrict it based on the IAM role the EC2 instance is using.

    1. Create an IAM EC2 Instance role for your EC2 instances.
    2. Run your EC2 instances using that role.
    3. Give this IAM role a policy to access the S3 bucket.

    For example:

    {
      "Version": "2012-10-17",
      "Statement":[{
        "Effect": "Allow",
        "Action": "s3:*",
        "Resource": ["arn:aws:s3:::my_bucket",
                     "arn:aws:s3:::my_bucket/*"]
        }
      ]
    } 
    
    1. If you want to restrict access to the bucket itself, try an S3 bucket policy.

    For example:

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Principal": {
            "AWS": ["arn:aws:iam::111122223333:role/my-ec2-role"]
          },
          "Action": "s3:*",
          "Resource": ["arn:aws:s3:::my_bucket",
                       "arn:aws:s3:::my_bucket/*"]
        }
      ]
    }
    

    Additional information: http://blogs.aws.amazon.com/security/post/TxPOJBY6FE360K/IAM-policies-and-Bucket-Policies-and-ACLs-Oh-My-Controlling-Access-to-S3-Resourc

    0 讨论(0)
  • 2020-12-01 11:53

    IAM role is the solution for you.

    You need create role with s3 access permission, if the ec2 instance was started without any role, you have to re-build it with that role assigned.

    Refer: Allowing AWS OpsWorks to Act on Your Behalf

    0 讨论(0)
提交回复
热议问题