I've followed an excellent guide (Serverless Stack) that creates a typical CRUD serverless infrastructure with a react frontend. It's using the Serverless Framework for AWS.
What I don't like is that to bootstrap the setup, there is a lot of manual clicking in GUIs (mostly Amazon's console interface) involved. I.e. the setup is not version controlled and is not easily reproducible. It would not be easy to extend it with a CI/CD process etc. In this example the following resources need to be setup manually:
The only resources that are being built from code are the serverless functions (lambdas) themselves, as well as API Gateway instances. This is what the serverless framework does using its serverless.yml file. But all of the above resources are not automatically created. They sometimes need to be referenced to using their ARNs, but they are not being created by the serverless.yml configuration. Running such a system in production (which relies heavily on the manual creation of services through GUIs) would seem risky.
I was thinking that a solution for this would be to use Terraform or Cloudformation. But the Serverless Framework itself is using Cloudformation for the setup of Lambdas already, though not for other resources. So how would one eliminate this gap? In other words, how would one rebuilt the entire setup described at Serverless Stack in code?
It would seem strange, and perhaps not possible, to have CloudFormation setup Serverless, which then has its own Cloudformation templates to setup lambdas. It might make more sense to extend the Serverless Framework to not just define the functions and API Gateways that need to be created on a serverless deploy
, but also other resources like a DynamoDB or a Cognito User Pool. Are there any examples or attempts of people doing this already?
Serverless Framework is open source. It's written using NodeJS and initially developed for building applications on AWS Platform and now it supports Azure, Google Cloud, Oracle Cloud and more. It handles most of the boilerplate code when it comes to generating infrastructure as code in each respective platform.
The four core components of serverless development are FaaS (Function As A Service), BaaS (Backend As A Service), API Gateway, and database.
Serverless architecture is an approach to software design that allows developers to build and run services without having to manage the underlying infrastructure. Developers can write and deploy code, while a cloud provider provisions servers to run their applications, databases, and storage systems at any scale.
You can build a serverless web application by using several AWS services together. Each service is fully managed and does not require you to provision or manage servers. You only need to configure them together and upload your application code to AWS Lambda, a serverless compute service.
I agree that documentation on this would make an excellent pull request here.
You're correct that serverless
is using CloudFormation under the hood. The framework does expose the underlying CloudFormation machinery to you, by way of the resources
key of your serverless.yml
.
I think the intent of the framework is that you would put the rest of these resources (Cognito stuff, S3, etc.) in the resources:
section of your serverless.yml
file, using regular old CloudFormation syntax.
For example, this file will create a DynamoDB table and S3 bucket, in addition to the serverless function:
service: aws-nodejs # NOTE: update this with your service name
provider:
name: aws
runtime: nodejs6.10
functions:
hello:
handler: handler.deletecustomer
events:
- http:
path: /deletecustomer
method: post
cors: true
resources:
Resources:
tablenotes:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: noteId
AttributeType: S
- AttributeName: userId
AttributeType: S
KeySchema:
- AttributeName: userId
KeyType: HASH
- AttributeName: noteId
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: '5'
WriteCapacityUnits: '5'
mysamplebucket:
Type: AWS::S3::Bucket
Properties:
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: error.html
AccessControl: Private
VersioningConfiguration:
Status: Suspended
If you're new to CloudFormation, I'd also recommend taking a peek at CloudFormer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With