Rocketsam
A CLI made to build and deploy microservices in AWS.
Currently the project supports lambda written in python 3.6/3.7 or node 8.1, but can easily be extended to support more languages in the future.
Whats new
1.0.38 +
template params default value changes will update the template accordingly
Why Rocketsam?
Good question, even though there are many third party solutions for deploying and building microservices on AWS, I found that they all lack some basic features.
Advantages of Rocketsam
- Template per function instead of gigantic template file (the CLI will append to the app skeleton each of the functions template)
- Caching per function, this CLI will upload only functions that their build output has changed (using hash validation).
- The build command support python/node dependencies (it will be installed using docker and cached in the build folder).
- Seamless deployment of the microservice using Cloud Formation.
- Easy access to API url's and logs of each function using logs and outputs commands.
- Running a local version of the server using SAM local.
For more info, run rocketsam help
Getting Started
npm install -g rocketsam
rocketsam init
rocketsam create hello
rocketsam add event api hello -e /hello
rocketsam build all
rocketsam invoke hello
rocketsam deploy
rocketsam outputs
rocketsam logs hello
Prerequisites
In order to use the CLI, one must install AWS SAM, as well as Docker (in order to spin a local server and to install dependencies)
sample projects
App structure
├── app
│ ├── common
│ │ └── service.py
│ ├── functions
│ │ └── sample
│ │ ├── common
│ │ │ └── service.py -> $/app/common/service.py
│ │ ├── function.py
│ │ ├── requirements.txt
│ │ └── template.yaml
│ ├── resources
│ │ ├── bucket.yaml
│ │ └── cognitopool.yaml
│ └── template-skeleton.yaml
└── rocketsam.yaml
The app folder consists of three main folders: common, functions and resources
common - contains files that can be shared across functions (more details below)
functions - contains dirs representing functions in the microservice.
resources - contains yaml files each treated as a resource in the resulting SAM template.
The function template file
Name: hello
Timeout: 10
Runtime: python3.7
Environment:
Variables:
demo: 1
Policies:
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 's3:*'
Resource:
- 'Fn::Sub': 'arn:aws:s3:::${bucketName}/*'
SammyApiEvent:
authorizerName: MyCognitoAuthorizer
path: /upload
method: post
SammyBucketEvent:
bucketName: MainBucket
bucketEvent: 's3:ObjectCreated:*'
Rules:
- Name: suffix
Value: .pdf
- Name: prefix
Value: uploads/
The way this template works is that the CLI has special keys: Name, SammyApiEvent and SammyBucketEvent which determine the name of the function in the template, an optional api event which called the function and an optional bucket event which trigger the function (if the bucket exist in the microservice and policies allow access). All other keys in the template will imported as is to the function part in the template (marked [ASIS]).
The Rocketsam config file
appDir: $/app
buildDir: $/.build
commonDir: $/app/common
resourcesDir: $/app/resources
storageBucketName: SampleBucket
storageBucketPrefix: SampleBucketFolderName
stackName: ABCD
region: eu-west-1
Other magic
In the app there is a special folder called common (can be defined in the rocketsam config). the files in these folder can be shared across functions using a special syntax placed at the top of the function code file.
For instance:
Will fetch from the common folder two files and placed them in the function resulting zip (can be viewed as symlinks in the function app dir)
The result:
This is not limited to python/node files only, you can place any files and reference them in the same way.
License
This project is licensed under the MIT License - see the LICENSE.md file for details