블로그 목록

AWS Amplify v4 → v6 마이그레이션 (Storage API)

2024-07-182 min read
AWS AmplifyAWS S3마이그레이션

partners-2에서 aws-amplify version을 변경하게 된 이유와 v4 → v6 사이의 주요 API 변경점을 정리한다.

버전비고
aws-amplify v44.3.14
aws-amplify v66.3.8

1. Amplify.config type

v4v6
config: anyconfig: ResourcesConfig | LegacyConfig | AmplifyOutputs

2. Storage S3 Upload

v4 — Storage.put

Storage.put(s3Key, file, {
  level,
  contentType: "image/*",
});

v6 — uploadData

const data = await uploadData({
  path,
  data: file,
  options: {
    contentType: "image/*",
  },
});

const { path } = await data.result;

3. Storage S3 Get

v4 — Storage.get

async function getStorage(s3FileLocation: S3FileLocation) {
  return (await Storage.get(s3FileLocation.key, {
    level: s3FileLocation.level,
    identityId: s3FileLocation.identityId,
    download: true,
  })) as unknown as { Body: Blob };
}

v6 — downloadData

async function getStorage(s3FileLocation: S3FileLocation) {
  const { body } = await downloadData({
    path: [s3FileLocation.level, s3FileLocation.key].join("/"),
  }).result;

  return body.blob();
}

4. Storage S3 Remove

v4 — Storage.remove

async function removeS3Image(key: string) {
  return Storage.remove(key);
}

v6 — remove

async function removeS3Image(key: string) {
  return remove({ path: ["public", key].join("/") });
}

5. S3 Key 표현 방식

v4v6
S3FileLocation 객체 (key, level, identityId)path (단순 string)

v6에서는 level과 key를 슬래시로 합쳐 단일 path 문자열로 다루는 형태로 단순화됐다.

참조