user2177118
user2177118

Reputation: 37

How to Get AWS IAM credentials of the ECS Instance its running within - using Java?

I'm struggling to get a S3Client having the credentials of the ECS Instance its running within.

The ECS instance has policy & trust as below - which I think is okay

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "s3:PutObject*",
            "Resource": [
                "arn:aws:s3:::myBucket",
                "arn:aws:s3:::/*"
            ]
        }
    ]
}
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "ec2.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]

I don't see how to get the client - In the .net world I would use

s3Client = Amazon.AWSClientFactor.CreateAmazonS3Client()

But I need to do this in Java - I have tried a number of ways but always get 'denied'

s3Client = AmazonS3ClientBuilder.standard().build();

Can any one point me at the corrects method & documentation?

Upvotes: 0

Views: 273

Answers (1)

jarmod
jarmod

Reputation: 78573

The IAM policy you are using is incorrect, specifically the resource. To indicate all objects in myBucket, use the following:

"Resource": "arn:aws:s3:::myBucket/*"

Upvotes: 1

Related Questions