serverless-s3-build-deploy v1.0.2
serverless-s3-build-deploy
Plugin for serverless to deploy files to a variety of S3 Buckets. Extends the orignal plugin by @funkybob to run scripts before uploading
Usage
Add to your serverless.yml:
plugins:
- serverless-s3-deploy
custom:
assets:
targets:
- bucket: my-bucket
run:
commands: yarn build
files:
- source: ../assets/
globs: '**/*.css'
- source: ../app/
globs:
- '**/*.js'
- '**/*.map'
- bucket: my-other-bucket
prefix: /subdir'
run:
commands:
- yarn test
- yarn build
cwd: /subdir/nested
files:
- source: ../email-templates/
globs: '**/*.html'You can specify any number of targets that you want. Each target has a
bucket and a prefix.
You can specify source relative to the current directory.
Each source has its own list of globs, which can be either a single glob,
or a list of globs.
Each target can have an option of run with an array of commands, which are executed before uploading any files. Usefull to build the frontend.
Optional inside the run option you can set the process working directory using cwd.
Now you can upload all of these assets to your bucket by running:
$ sls s3delpoyIf you have defined multiple buckets, you can limit your deployment to
a single bucket with the --bucket option:
$ sls s3deploy --bucket my-bucketACL
You can optionally specificy an ACL for the files uploaded on a per target basis:
custom:
assets:
targets:
- bucket: my-bucket
acl: private
files:The default value is public-read. Options are defined
here.
Content Type
The appropriate Content Type for each file will attempt to be determined using
mime-types. If one can't be determined, a default fallback of
'application/octet-stream' will be used.
You can override this fallback per-source by setting defaultContentType.
custom:
assets:
targets:
- bucket: my-bucket
files:
- source: html/
defaultContentType: text/html
...Other Headers
Additional headers can be included per target by providing a headers object.
See http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html for more details.
custom:
assets:
targets:
- bucket: my-bucket
files:
- source: html/
headers:
CacheControl: max-age=31104000 # 1 yearAuto-deploy
If you want s3deploy to run automatically after a deploy, set the auto flag:
custom:
assets:
auto: trueIAM Configuration
You're going to need an IAM policy that supports this deployment. This might be a good starting point:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::${bucket}"
]
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:PutObjectAcl",
"s3:GetObject",
"s3:DeleteObject"
],
"Resource": [
"arn:aws:s3:::${bucket}/*"
]
}
]
}