S3にファイルをアップロードしてくれるserverless-s3-syncというプラグインがあり。
フォルダを指定すると、その中身がアップロードされるのだが、指定フォルダの中にフォルダを配置すると、そのフォルダもアップロードしてくれました。
インストールコマンドは以下、
service: sls-${self:custom.project}-s3
localDir: が指定する、staticというフォルダの中に、フォルダとファイルを配置しました。
plugins:
- serverless-s3-sync
custom:
name: testbucket
s3Sync:
- bucketName: ${self:custom.name}
localDir: static
resources:
Resources:
S3bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: PublicRead
BucketName: ${self:custom.name}
PublicAccessBlockConfiguration:
BlockPublicAcls: True
BlockPublicPolicy: False
IgnorePublicAcls: True
RestrictPublicBuckets: True
StaticSiteS3BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket:
Ref: S3bucket
PolicyDocument:
Statement:
-
Effect: Allow
Principal: "*"
Action:
- s3:GetObject
Resource:
- arn:aws:s3:::${self:custom.name}/*