Is there a way to curl an S3 bucket from an EC2 instance

Viewed 27

I am trying to send a curl request to an S3 bucket to retrieve a specific object within the bucket:

The EC2 instance (Linux machine) works as a proxy server with NGINX to send HTTP requests to the bucket, I do not have an SSL cert on this instance.

The curl request looks like this:

curl my-bucket.s3.eu-west-1.amazonaws.com/1450/1349/5467_1012.jpg

But I get an Access Denied error

I have attached a full read access policy to my EC2 instance role.

I'm thinking it might be my bucket policy:

{
"Version": "2012-10-17",
"Id": "MediaStorageBucketPolicy",
"Statement": [
    {
        "Effect": "Allow",
        "Principal": {
            "AWS": "arn:aws:iam::${current_account}:root"
        },
        "Action": [
            "s3:GetObject",
            "s3:ListBucket"
        ],
        "Resource": [
            "${media_storage_bucket_arn}",
            "${media_storage_bucket_arn}/*"
        ]
    },
    {
        "Effect": "Allow",
        "Principal": {
            "AWS": "arn:aws:iam::${current_account}:root"
        },
        "Action": [
            "s3:PutObject"
        ],
        "Resource": [
            "${media_storage_bucket_arn}",
            "${media_storage_bucket_arn}/*"
        ]
    },

{
    "Effect": "Allow",
    "Principal": {
        "AWS": [
            "arn:aws:I am::<my account number>:role/ssm-ec2-service-role"
        ]
    },
    "Action": [
        "s3:GetObject",
        "s3:ListBucket"
    ],
    
    "Resource": [
        "${media_storage_bucket_arn}",
        "${media_storage_bucket_arn}/*"
    ]
}


]

}

Any ideas?

0 Answers
Related