Setting up an S3 bucket and CloudFront distribution to host static media isn't complicated and, in theory, we could add this to the Resources
section of our serverless.yml
file. The ability of Serverless to manage so many resources via CloudFormation
is a slippery slope, since setting up systems can quickly become an exercise in learning and debugging CloudFormation
. Another downside of a growing Resources
section in the serverless.yml
file is that deployments will take longer and longer. It's possible to only deploy application code during development, which results in single-digit second deployments; but when some system resource is updated, including environment variables, the entire CloudFormation
stack needs to updated.
Rather than creating the S3 bucket and CloudFront distribution via serverless.yml
, we can use a separate CloudFormation
template designed just for this purpose. Another reason for splitting this out into a separate step is that this layer rarely...