Access denied to S3 bucket from AWS CLI

0

Hi,

I'm able to access a S3 bucket from the console. But when I try to use AWS CLI command 'aws s3 ls s3://<bucket name>/, I get message 'An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied'. The CLI profile region is the same as the S3 bucket region. The access key and secret access key are all correct. What could I have missed? Thanks.

3개 답변
0
수락된 답변

Thanks all for your advice. Root cause was identified and issue was resolved now. The MFA was enforced in CLI and temporary token was not setup in the profile hence unable to access the AWS services from CLI. The MFA enforcement has been removed for the AWS service I need to access in CLI and it's working now.

답변함 일 년 전
profile picture
전문가
검토됨 한 달 전
0

Hi, You should verify that your cli profile is known:

aws configure list-profiles

then check the identity under which you will run your cli command:

aws sts get-caller-identity

Finally, you may run

aws sts get-caller-identity --profile (name of the profile you want to view)
profile pictureAWS
전문가
답변함 일 년 전
  • Hi Didier, thanks for the quick response. The result from running the first command above is 'default'. And when I run the 3rd command 'aws sts get-caller-identity --profile default', I got the same result as the 2nd command.

  • Ok. Good. Is then 'default' the profile containing the access / secret key that you expect ? If yes, check in IAM console that this key pair is attached to the user that you use in the console. That will ensure that the console credentials that work apply also to key pair in default profile.

0

Hi,

Could you check if your IAM user has the required permission to access the bucket? You will need a policy similar to the following to access the bucket objects

{
  "Version": "2012-10-17",
  "Statement": [
      {
          "Effect": "Allow",
          "Action": [
              "s3:ListBucket"
          ],
          "Resource": [
              "arn:aws:s3:::bucketname"
          ]
      },
      {
          "Effect": "Allow",
          "Action": [
              "s3:GetObject"
          ],
          "Resource": [
              "arn:aws:s3:::bucketname/*"
          ]
      }
  ]
}
profile picture
Bisina
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠