Notice
Recent Posts
Recent Comments
Link
투케이2K
179. (Aws/Amazon) [Aws S3 Storage] AWS S3 특정 버킷 CORS (Cross-Origin) 규칙 조회 GetBucketCors API 설명 정리 본문
Aws (Amazon)
179. (Aws/Amazon) [Aws S3 Storage] AWS S3 특정 버킷 CORS (Cross-Origin) 규칙 조회 GetBucketCors API 설명 정리
투케이2K 2026. 2. 5. 20:29728x90
[개발 환경 설정]
개발 환경 : Aws / Amazon Web Services

[설명 정리]
// --------------------------------------------------------------------------------------
[개발 및 환경]
// --------------------------------------------------------------------------------------
- 인프라 : Aws / Amazon Web Services
- 기술 구분 : Aws / S3 / CORS / GetBucketCors
- 사전) S3 개념 정리 :
>> AWS S3 (Amazon Simple Storage Service) 는 AWS 에서 제공하는 객체 스토리지 서비스로, 인터넷을 통해 데이터를 저장하고 검색할 수 있도록 설계되었습니다
>> 기본 용어 정리 :
- 객체(Object): S3에 저장되는 데이터 단위. 파일과 메타데이터로 구성됩니다
- 버킷(Bucket): 객체를 저장하는 컨테이너. S3에서 데이터를 저장하려면 먼저 버킷을 생성해야 합니다
- 키(Key): 객체를 식별하는 고유한 이름. 버킷 내에서 객체를 구분하는 데 사용됩니다
// --------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------
[설 명]
// --------------------------------------------------------------------------------------
1. AWS S3 GetBucketCors 는 S3 버킷에 설정된 CORS(Cross-Origin Resource Sharing) 규칙을 조회하는 API 입니다
2. AWS S3 GetBucketCors API 호출을 통해 S3 버킷의 CORS 설정 (JSON/XML 형식의 규칙) 을 가져오며, 브라우저에서 크로스 도메인 요청을 허용할지 여부 등을 지정한 구성을 확인할 수 있습니다
3. AWS S3 GetBucketCors API 가 제공하는 내용 간략 정리 :
>> 버킷에 적용된 CORSConfiguration 전체 반환
>> 반환 형태 : <CORSConfiguration> → <CORSRule> 목록 구조(XML 기반)
>> 규칙에는 AllowedOrigin, AllowedMethod, AllowedHeader, ExposeHeader, MaxAgeSeconds, ID 등이 포함
4. AWS S3 GetBucketCors API 호출 Request , Response 전문 예시 :
// ✅ Request 전문 예시
GET /?cors HTTP/1.1
Host: Bucket.s3.amazonaws.com
x-amz-expected-bucket-owner: ExpectedBucketOwner
// ✅ Response 전문 예시
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>...</AllowedOrigin>
<AllowedMethod>...</AllowedMethod>
<AllowedHeader>...</AllowedHeader>
<ExposeHeader>...</ExposeHeader>
<MaxAgeSeconds>...</MaxAgeSeconds>
<ID>...</ID>
</CORSRule>
</CORSConfiguration>
5. AWS S3 GetBucketCors 호출 주요 에러 코드 정리 :
>> InvalidAccessPointAliasError : Access point 또는 Object Lambda Access Point alias가 잘못된 값인 경우 발생
>> AccessDenied : 호출 주체(IAM User/Role)에 s3:GetBucketCORS 권한이 없는 경우
>> NoSuchCORSConfiguration : 버킷에 CORS 설정이 전혀 존재하지 않을 때 발생
>> URI/Parameter Errors (URL Encoding 이슈) : 인코딩이 올바르지 않으면 요청이 거부될 수 있음
6. AWS S3 GetBucketCors 호출 자바스크립트 예시 코드 :
<!-- [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'
};
// -----------------------------------------
// [GetBucketCors] : 지정된 S3 버킷에 설정된 CORS(Cross-Origin Resource Sharing) 규칙을 조회
// -----------------------------------------
// AWS 참고 사이트 : https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketCors.html
// -----------------------------------------
aws.getBucketCors( params , function(err, data) {
if (err) {
console.error("[getBucketCors] : [Error] : ", err);
} else {
console.log("[getBucketCors] : [Result] : ", JSON.stringify(data));
// ---------------------------------------------
// ✅ [로그 출력 예시 첨부]
// ---------------------------------------------
/*
{
"CORSRules": [
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [
"ETag",
"x-amz-meta-custom-header"
]
}
]
}
*/
// ---------------------------------------------
}
});
// --------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------
[참고 사이트]
// --------------------------------------------------------------------------------------
[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
[유틸 파일] deleteS3File - Aws S3 버킷 저장소 파일 삭제 수행 - AmazonS3 File Delete
https://blog.naver.com/kkh0977/223797286196?trackingCode=blog_bloghome_searchlist
// --------------------------------------------------------------------------------------
728x90
반응형
'Aws (Amazon)' 카테고리의 다른 글
Comments
