Serverless framework does a lot of magic (not in a bad way) to make your life easy while deploying serverless projects. Serverless or sls
in short, packages your application and uses s3 bucket to deploy your application. It doesn't ask you what the name should be, but infers it based on your service name and some random strings to come up with the S3 bucket name. Just give name which exists in your s3.
service: cool-service
provider:
name: aws
runtime: nodejs12.x
region: ap-southeast-2
...
If your serverless.yml
looks like above, you might get a bucket name like cool-service-prod-serverlessdeploymentbucket-<random string>
. No problem with that. All good! If you have 1000 serverless projects in one account, you will need 1000 s3 buckets for sls deployment and you cannot have more than 1000 s3 buckets in an AWS account. That's when you would think of reusing the s3 buckets. And here is how to do it by using a key in the serverless.yml
file.
service: cool-service
provider:
name: aws
runtime: nodejs12.x
deploymentBucket:
name: all-service-deployments # Deployment bucket name. Default is generated by the framework
maxPreviousDeploymentArtifacts: 10 # On every deployment the framework prunes the bucket to remove artifacts older than this limit. The default is 5
blockPublicAccess: true # Prevents public access via ACLs or bucket policies. Default is false
serverSideEncryption: AES256 # server-side encryption method
sseKMSKeyId: arn:aws:kms:us-east-1:xxxxxxxxxxxx:key/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa # when using server-side encryption
sseCustomerAlgorithim: AES256 # when using server-side encryption and custom keys
sseCustomerKey: string # when using server-side encryption and custom keys
sseCustomerKeyMD5: md5sum # when using server-side encryption and custom keys
tags: # Tags that will be added to each of the deployment resources
key1: value1
key2: value2
It will store all your deployment packages in subfolders in the s3 bucket.
Top comments (1)
Hi Dina,
seems like some of the attribute keys related to the bucket are not correct here. I had to use the ones found in Cloudformation.
Example:
SSEAlgorithm: "aws:kms"
KMSMasterKeyID: ${env:DEPLOYMENT_BUCKET_KMS}