Notice
Recent Posts
Recent Comments
Link
투케이2K
180. (Aws/Amazon) [Aws S3 Storage] AWS S3 특정 버킷 정책 (Bucket Policy) 조회 GetBucketPolicy API 설명 정리 본문
Aws (Amazon)
180. (Aws/Amazon) [Aws S3 Storage] AWS S3 특정 버킷 정책 (Bucket Policy) 조회 GetBucketPolicy API 설명 정리
투케이2K 2026. 2. 6. 20:17728x90
[개발 환경 설정]
개발 환경 : Aws / Amazon Web Services

[설명 정리]
// --------------------------------------------------------------------------------------
[개발 및 환경]
// --------------------------------------------------------------------------------------
- 인프라 : Aws / Amazon Web Services
- 기술 구분 : Aws / S3 / CORS / GetBucketPolicy
- 사전) S3 개념 정리 :
>> AWS S3 (Amazon Simple Storage Service) 는 AWS 에서 제공하는 객체 스토리지 서비스로, 인터넷을 통해 데이터를 저장하고 검색할 수 있도록 설계되었습니다
>> 기본 용어 정리 :
- 객체(Object): S3에 저장되는 데이터 단위. 파일과 메타데이터로 구성됩니다
- 버킷(Bucket): 객체를 저장하는 컨테이너. S3에서 데이터를 저장하려면 먼저 버킷을 생성해야 합니다
- 키(Key): 객체를 식별하는 고유한 이름. 버킷 내에서 객체를 구분하는 데 사용됩니다
// --------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------
[설 명]
// --------------------------------------------------------------------------------------
1. AWS S3 GetBucketPolicy 는 S3 버킷에 설정된 버킷 정책 (Bucket Policy) 을 조회하는 API 입니다
2. AWS S3 버킷 정책은 JSON 기반의 리소스 정책 (Resource-based policy) 으로, 누가(bucket-level) 어떤 작업을 어떤 조건에서 수행할 수 있는지를 정의합니다
3. AWS S3 GetBucketPolicy API 가 제공하는 반환 내용 간략 정리 :
>> 버킷에 설정된 정책 JSON 전체
>> 응답은 GetBucketPolicyResult.Policy 형태로 제공
>> 정책이 존재하지 않는 경우 오류 반환(일반적으로 NoSuchBucketPolicy)
4. AWS S3 GetBucketPolicy API 호출 Request , Response 전문 예시 :
// ✅ Request 전문 예시 : s3:GetBucketPolicy 권한이 필요
GET /?policy HTTP/1.1
Host: Bucket.s3.amazonaws.com
x-amz-expected-bucket-owner: ExpectedBucketOwner
// ✅ Response 전문 예시
{
"Policy": "{... 버킷 정책 JSON 문자열 ... }"
}
5. AWS S3 GetBucketPolicy 호출 주요 에러 코드 정리 :
>> AccessDenied : 호출자가 s3:GetBucketPolicy 권한 없음
>> MethodNotAllowed : 호출자가 버킷 소유 계정이 아닌 경우
>> NoSuchBucketPolicy : 버킷에 정책이 전혀 없는 경우
>> InvalidAccessPointAliasError : Access Point 또는 Object Lambda Access Point alias가 잘못된 경우
6. AWS S3 GetBucketPolicy 호출 자바스크립트 예시 코드 :
<!-- [CDN 주소 설정] -->
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1416.0.min.js"></script>
// [전역 변수 선언]
const region = 'ap-northeast-2';
const accessKey = 'AK..A6';
const secretKey = 'mP..5J';
// -----------------------------------------
// [AWS.config 지정]
// -----------------------------------------
AWS.config.update({
region: region,
accessKeyId: accessKey,
secretAccessKey: secretKey
});
// -----------------------------------------
// [AWS 객체 생성]
// -----------------------------------------
const aws = new AWS.S3();
// -----------------------------------------
// [요청 파라미터 생성]
// -----------------------------------------
const param = { // ✅ 버킷 명칭 지정
Bucket: 'service'
};
// -----------------------------------------
// [GetBucketPolicy] : S3 버킷에 설정된 버킷 정책 조회 수행
// -----------------------------------------
// AWS 참고 사이트 : https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketPolicy.html
// -----------------------------------------
aws.getBucketPolicy( params , function(err, data) {
if (err) {
console.error("[getBucketPolicy] : [Error] : ", err);
} else {
console.log("[getBucketPolicy] : [Result] : ", JSON.stringify(data));
// ---------------------------------------------
// ✅ [로그 출력 예시 첨부]
// ---------------------------------------------
/*
{
"Version": "2012-10-17",
"Id": "Policy1642054460770",
"Statement": [
{
"Sid": "Stmt1642054438498",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::service-notice/*"
},
{
"Sid": "RestrictToTLSRequestsOnly",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::service-notice",
"arn:aws:s3:::service-notice/*"
],
"Condition": {
"Bool": {
"aws:SecureTransport": "false"
}
}
}
]
}
*/
// ---------------------------------------------
}
});
// --------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------
[참고 사이트]
// --------------------------------------------------------------------------------------
[Aws S3 Storage] AWS 콘솔에서 S3 버킷 저장소 CORS 설정 JSON 정보 확인 방법 정리
https://kkh0977.tistory.com/8608
https://blog.naver.com/kkh0977/224171842021
[Aws S3 Storage] S3 (Amazon Simple Storage Service) 버킷 저장소 개념 및 설명 정리
https://kkh0977.tistory.com/7619
https://blog.naver.com/kkh0977/223733087281?trackingCode=blog_bloghome_searchlist
[유틸 파일] getS3FileUpload - Aws S3 버킷 저장소 파일 업로드 수행 - AmazonS3 File Upload
https://blog.naver.com/kkh0977/223797276630?trackingCode=blog_bloghome_searchlist
[유틸 파일] getS3FileDownload - Aws S3 버킷 저장소 파일 다운로드 수행 - AmazonS3 File Download
https://blog.naver.com/kkh0977/223797282036?trackingCode=blog_bloghome_searchlist
[유틸 파일] deleteS3File - Aws S3 버킷 저장소 파일 삭제 수행 - AmazonS3 File Delete
https://blog.naver.com/kkh0977/223797286196?trackingCode=blog_bloghome_searchlist
// --------------------------------------------------------------------------------------
728x90
반응형
'Aws (Amazon)' 카테고리의 다른 글
Comments
