Access denied error when sending curl to S3 bucket

Viewed 37

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

I want to create a transparent proxy with caching implemented by nginx so the aws cli wont work for this.

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

The bucket only contains images.

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.

Here is 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::<account number>:role/ssm-ec2-service-role"
            ]
        },
        "Action": [
            "s3:GetObject",
            "s3:ListBucket"
        ],
        
        "Resource": [
            "${media_storage_bucket_arn}",
            "${media_storage_bucket_arn}/*"
        ]
    }


    ]
}

Can this be achieved without making the bucket public?

1 Answers
Related