Serverless에서 S3 설정하기
This chapter has been archived and is no longer updated. View the current version of the guide.
S3를 serverless에서 설정하기
이제 DynamoDB 설정을 마쳤으니, serverless.yml을 통해 S3 파일 업로드 버킷을 설정하는 방법을 살펴보겠습니다.
리소스 생성
resources/s3-bucket.yml에 다음 내용을 추가합니다.
Resources:
AttachmentsBucket:
Type: AWS::S3::Bucket
Properties:
# CORS 정책 설정
CorsConfiguration:
CorsRules:
-
AllowedOrigins:
- '*'
AllowedHeaders:
- '*'
AllowedMethods:
- GET
- PUT
- POST
- DELETE
- HEAD
MaxAge: 3000
# 생성된 버킷 이름 출력
Outputs:
AttachmentsBucketName:
Value:
Ref: AttachmentsBucket
파일 업로드를 위한 S3 버킷 생성 챕터에서 다뤘던 것처럼, 버킷을 생성하고 CORS 정책을 설정했습니다. 프론트엔드 클라이언트에서 직접 업로드할 예정이기 때문에 이 정책이 필요했습니다. 여기서도 동일한 정책을 설정합니다.
DynamoDB 테이블과 달리 S3 버킷은 전역적으로 이름이 지정되기 때문에, 버킷 이름을 미리 알 수 없습니다. 따라서 CloudFormation이 이름을 생성하도록 하고, 나중에 사용할 수 있도록 Outputs: 블록을 추가해 이름을 출력합니다.
리소스 추가하기
serverless.yml에서 리소스를 참조해 보겠습니다. resources: 블록을 다음으로 교체하세요.
# 별도의 CloudFormation 템플릿으로 리소스 생성
resources:
# DynamoDB
- ${file(resources/dynamodb-table.yml)}
# S3
- ${file(resources/s3-bucket.yml)}
이제 끝났습니다. 다음으로 Cognito 사용자 풀 설정을 살펴보겠습니다.
For help and discussion
Comments on this chapter