250x250
반응형
arkhyeon
arkhyeon
arkhyeon
전체 방문자
오늘
어제
  • 분류 전체보기 (88)
    • Spring (5)
    • Java (4)
    • React (25)
      • TypeScript (6)
      • JavaScript (1)
      • Jest (9)
    • NEXT (8)
    • SQL (1)
    • React native (1)
    • CSS (3)
    • Web (1)
    • Git (3)
    • ETC (6)
    • 빅데이터DB (8)
    • Docker (4)
    • Tool (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • Spring WebSocket
  • react spring websocket
  • WSS
  • javasciprt websocket
  • javascript wss
  • react19
  • jest
  • react usetransition
  • websocket
  • react typescript
  • react
  • react loading
  • react websocket
  • react jest
  • node WebSocket
  • usetransition
  • HIVE
  • kudu
  • websocket server
  • docker tomcat

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
arkhyeon

arkhyeon

NEXT

AWS S3 Access Denied CopyObjectCommand

2024. 10. 18. 13:53
728x90
반응형

CopySource에 복사 경로 + 원본 파일명만 적었는데 Bucket 이름까지 작성해야한다.

S3 예제 코드

const input = {
  "Bucket": "destinationbucket",
  "CopySource": "/sourcebucket/HappyFacejpg",
  "Key": "HappyFaceCopyjpg"
};
const command = new CopyObjectCommand(input);
const response = await client.send(command);

작성 코드

const Bucket = process.env.AMPLIFY_BUCKET;
const s3 = new S3Client({
  region: process.env.AWS_REGION,
  credentials: {
    accessKeyId: process.env.AWS_ACCESS_KEY_ID as string,
    secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY as string,
  },
});

await s3.send(
  new CopyObjectCommand({
    Bucket: ,
    CopySource: Bucket + '/' + originFileName,
    Key: copyFileName,
  }),
);

권한 - 버킷 정책

// BUCKET NAME, ACCOUNT ID 작성 요망
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "1",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::[BUCKET NAME]/*"
        },
        {
            "Sid": "2",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::[ACCOUNT ID]:root"
            },
            "Action": [
                "s3:PutObject",
                "s3:DeleteObject"
            ],
            "Resource": "arn:aws:s3:::[BUCKET NAME]/*"
        }
    ]
}

이미지 업로드할 때 먼저 temp 폴더에 업로드 후 게시물 저장 로직에 temp 폴더에서 실제 저장소로 이미지를 복사 후 temp 폴더의 이미지를 제거했을 때 일어난 오류였다.

728x90
반응형

'NEXT' 카테고리의 다른 글

Only plain objects, and a few built-ins, can be passed to Server Actions.  (0) 2024.10.08
NEXT JS + Google Analytics Connect Setting  (0) 2024.08.07
Parallel Routes Modal Difficult Error  (0) 2024.07.25
NextJs Next-auth getSession() 로그인 정보 확인  (0) 2024.07.23
NEXT 14 NEXT-AUTH 5 middleware.ts not working  (0) 2024.07.11
    'NEXT' 카테고리의 다른 글
    • Only plain objects, and a few built-ins, can be passed to Server Actions.
    • NEXT JS + Google Analytics Connect Setting
    • Parallel Routes Modal Difficult Error
    • NextJs Next-auth getSession() 로그인 정보 확인
    arkhyeon
    arkhyeon

    티스토리툴바