Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied

I was struggling with this, too, but I found an answer over here https://stackoverflow.com/a/17162973/1750869 that helped resolve this issue for me. Reposting answer below.


You don't have to open permissions to everyone. Use the below Bucket policies on source and destination for copying from a bucket in one account to another using an IAM user

Bucket to Copy from – SourceBucket

Bucket to Copy to – DestinationBucket

Source AWS Account ID - XXXX–XXXX-XXXX

Source IAM User - src–iam-user

The below policy means – the IAM user - XXXX–XXXX-XXXX:src–iam-user has s3:ListBucket and s3:GetObject privileges on SourceBucket/* and s3:ListBucket and s3:PutObject privileges on DestinationBucket/*

On the SourceBucket the policy should be like:

{ "Id": "Policy1357935677554", "Statement": [ { "Sid": "Stmt1357935647218", "Action": [ "s3:ListBucket" ], "Effect": "Allow", "Resource": "arn:aws:s3:::SourceBucket", "Principal": {"AWS": "arn:aws:iam::XXXXXXXXXXXX:user/src–iam-user"} }, { "Sid": "Stmt1357935676138", "Action": ["s3:GetObject"], "Effect": "Allow", "Resource": "arn:aws:s3::: SourceBucket/*", "Principal": {"AWS": "arn:aws:iam::XXXXXXXXXXXX:user/src–iam-user"} } ] }

On the DestinationBucket the policy should be:

{ "Id": "Policy1357935677554", "Statement": [ { "Sid": "Stmt1357935647218", "Action": [ "s3:ListBucket" ], "Effect": "Allow", "Resource": "arn:aws:s3::: DestinationBucket", "Principal": {"AWS": "arn:aws:iam::XXXXXXXXXXXX:user/src–iam-user"} }, { "Sid": "Stmt1357935676138", "Action": ["s3:PutObject"], "Effect": "Allow", "Resource": "arn:aws:s3::: DestinationBucket/*", "Principal": {"AWS": "arn:aws:iam::XXXXXXXXXXXX:user/src–iam-user"} } ] }

command to be run is s3cmd cp s3://SourceBucket/File1 s3://DestinationBucket/File1

Hi,

Kindly note ListObjects or ListObjectsV2 is the name of the API call that lists the objects in a bucket. You will need to use s3:ListBucket in the action element to allow a user to list the objects in a bucket.

https://aws.amazon.com/premiumsupport/knowledge-center/s3-access-denied-listobjects-sync/

Here is how I would write the policy to list the objects in a bucket.

{
"Version": "2012-10-17",
"Id": "S3PolicyId1",
"Statement": [
{
"Sid": "AllowList",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::bucketname"
}
]
}

Regards,
Pavithra

Hello jehake, Has your problem of your code been resolve? Let us know. Also, remember to click on the "Accept" button when an answer provided in the community helped you. This allows other community members to also benefit from it. Thank you for your participation.

SUPPORT ENGINEER

answered 3 months ago

Tech Note 정보 카테고리: [ Amazon Web Services ] 게시됨: 20 July 2019 작성됨: 19 July 2019 최종 변경: 20 July 2019 조회수: 4150

1. 개요

두 계정의 Bucket간 sync 정리

A 계정의 bucket에서 B 계정의 bucket sync하는 예

2. 전제조건

B 계정이 A 계정의 Bucket에 대한 권한이 있어야 한다.

3. 커맨드

$ aws s3 sync s3://BucketA s3://BucketB

5. 문제

5-1. An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied

B 계정에 특정 버킷에 대한 ListBucket 권한이 있는지 확인. 예를 들어 Bucket1에 대해서라면,

{ "Effect": "Allow", "Action": [ "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::BucketA" ] },

주의할 것은 ListBucket은 Bucket1 이지 Bucket1/*이 아니라는 것이다.

5-2. An error occurred (AccessDenied) when calling the CreateMultipartUpload operation: Access Denied

aws s3 sync 시 이런 문제가 발생한다면 BucketA, 즉 Source bucket에도 PutObject 권한이 있는지 확인.

venh.log

  • 관리
  • 글쓰기
  • 로그인
  • 로그아웃

  • 태그

▼ DevOps/AWS

by 아기상어 뚜루루뚜루 2021. 7. 14.

728x90

반응형

시작하기 전 CLI(명령줄 인터페이스)를 통해 S3 버킷에 액세스를 하려면
IAM 자격증명을 통해 액세스 키를 먼저 발급받아야 한다.

IAM 계정이 생성되지 않았으면 생성부터 하고 진행한다.

AWS | IAM 계정 생성 (그룹, 역할, 정책)

IAM(Identity and Access Managemnet)이란? AWS의 리소스에 대한 접근제어와 권한을 가지도록 계정 또는 그룹을 생성하는 서비스이다. IAM 계정에 따라 EC2 서비스만 접근할 수 있도록 권한을 부여하고, 다른

kitty-geno.tistory.com

Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
액세스 키를 발급받지 않은 경우 아래와 같은 메시지가 출력된다.

An error occurred (InvalidAccessKeyId) when calling ther ListBuckets operation: The AWS Access Key Id you provided does not exist in our records.

Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied

구성 및 자격 증명 설정
https://docs.aws.amazon.com/ko_kr/cli/latest/userguide/cli-configure-files.html
이름 설명
AWS Access Key ID IAM 액세스 키
WS Secret Access Key IAM 비밀 키
Default regio name 리전
Default output format 포맷 형식
aws configure
Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
버킷 및 객체 나열

정상적으로 버킷이 출력되면 구성 및 자격 증명 설정이 완료됐다.

aws s3 ls
Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
Access Denied(액세스 거부)
Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
Access Denied) 발생 시 해결방법 1

IAM 계정에 S3 정책이 허용되어있는지 확인한다.
안되어있을 경우 인라인 정책 추가 부분을 확인한다.

13번 인라인 정책 추가 확인

Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
Access Denied) 발생 시 해결방법 2

해당 버킷에 버킷 정책을 직접 추가한다.

버킷 상세페이지에서 권한 탭으로 이동한다.
Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
버킷 정책의 편집을 들어간다.
Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
버킷 ARN(①)을 복사한 상태로 정책 생성기(②)를 클릭한다.
Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
AWS Policy Generator

Select Type of Policy :

정책 타입

Effect : 버킷에 대한 명령을 허용(Allow)할 것인지 거부(Deny)할 것인지에 대한 옵션
Principal : 특정 사용자에 대해 권한을 제어하고 싶다면 입력한다.
(전체 : * / 특정 사용자 : arn:aws:iam:AWS-account-ID:user/IAMID)

AWS Service : 정책 타입 선택 시 자동 지정되는 서비스
Actions : 버킷에 대해 어떤 작업을 허용(또는 거부)할 것인지 선택하는 옵션
Amazon Resource Name(ARN) : 접근 권한을 주고자 하는 버킷 ARN (arn:aws:s3:::버킷명/*), 버킷 ARN(①)

모두 입력 후 Add Statement

Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
Generate Policy로 생성된내용을 복사한다.
Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
위에서 복사한 Policy JSON을 버킷 정책 편집 정책에 붙여 넣은 후 변경 사항을 저장한다.
Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied

테스트 목적으로 / 경로에 fileCopy 디렉터리를 생성한다.
mkdir fileCopy
객체 동기화

aws s3 sync <source> <target> [--options]

버킷과 디렉터리의 내용 또는 두 버킷의 내용을 동기화한다.
즉 버킷에 있는 파일들을 타깃 경로에 다운로드한다.

aws s3 sync s3://s3bucketven /fileCopy
버킷에 있는 파일들이 fileCopy 경로에 다운로드된 것을 볼 수 있다.
Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied

Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
버킷에 있는 파일을 디렉터리에 복사하는 명령어

aws s3 cp <source> <target>

aws s3 cp s3://s3bucketven/test/second.html /fileCopy/test/
Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied

#Reference
https://docs.aws.amazon.com/ko_kr/cli/latest/userguide/cli-services-s3-commands.html

AWS CLI에서 상위 수준(s3) 명령 사용 - AWS 명령줄 인터페이스

PowerShell을 사용하는 경우 셸은 CRLF의 인코딩을 변경하거나, 파이프 입력이나 출력 또는 리디렉션된 출력에 CRLF를 추가할 수 있습니다.

docs.aws.amazon.com

https://aws.amazon.com/premiumsupport/knowledge-center/ec2-instance-access-s3-bucket/?nc1=h_ls 

S3 버킷에 대한 EC2 인스턴스 액세스 권한 부여

Amazon Elastic Compute Cloud(Amazon EC2) 인스턴스에서 Amazon Simple Storage Service(Amazon S3) 버킷에 액세스할 수 없습니다. EC2 인스턴스에서 S3 버킷에 대한 읽기/쓰기 액세스를 활성화하려면 어떻게 해야 하나

aws.amazon.com

Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied

728x90

반응형

저작자표시비영리변경금지

'▼ DevOps > AWS' 카테고리의 다른 글

AWS | EC2 인스턴스 키 페어 추가, SSH 접속하기  (2) 2021.07.15
AWS | EC2 Apache(아파치) 설치 및 Tomcat(톰캣) 연동  (5) 2021.07.14
AWS | CLI를 이용하여 S3 버킷 액세스, 파일 업로드, 다운로드하기  (0) 2021.07.14
AWS | S3 버킷 생성  (0) 2021.07.14
AWS | EC2에 IAM 역할 추가 및 콘솔 접속  (0) 2021.07.13
AWS | IAM 계정 생성 (그룹, 역할, 정책)  (3) 2021.07.13

태그

aws s3 sync, CLI를 이용하여 S3 버킷 액세스, 다운로드하기, 파일 업로드

관련글

  • Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
    AWS | EC2 인스턴스 키 페어 추가, SSH 접속하기
  • Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
    AWS | EC2 Apache(아파치) 설치 및 Tomcat(톰캣) 연동
  • Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
    AWS | S3 버킷 생성
  • Aws s3 ls an error occurred (accessdenied) when calling the listbuckets operation: access denied
    AWS | EC2에 IAM 역할 추가 및 콘솔 접속

댓글0

비밀글

이전 1 ··· 95 96 97 98 99 100 101 102 103 ··· 164 다음


Why S3 Access Denied?

If you're getting Access Denied errors on public read requests that are allowed, check the bucket's Amazon S3 Block Public Access settings. Review the S3 Block Public Access settings at both the account and bucket level. These settings can override permissions that allow public read access.

Why am I getting an access denied error for ListObjectsV2 when I run the sync command on my Amazon S3 bucket?

If your bucket belongs to another AWS account and has Requester Pays enabled, verify that your bucket policy and IAM permissions both grant ListObjectsV2 permissions. If the ListObjectsV2 permissions are properly granted, then check your sync command syntax.

What permissions does S3 sync need?

To run the command aws s3 sync, then you need permission to s3:GetObject, s3:PutObject, and s3:ListBucket. Note: If you're using the AssumeRole API operation to access Amazon S3, you must also verify that the trust relationship is configured correctly.

How can I grant a user Amazon S3 console access to only a certain bucket?

To limit a user's S3 console access to a certain bucket or folder (prefix), change the user's AWS Identity and Access Management (IAM) permissions. You can change the IAM permissions by performing the following: 1. Remove permission to the s3:ListAllMyBuckets action.