Easiest way to deploy API services using Serverless Framework — Part 1
In this article we will demonstrate integration of Serverless Framework with Kumologica Designer. We will create simple hello world api, generate serverless.yml file and deploy flow to AWS account using Serverless Framework.
This is first article of the Kumologica DevOps series.
If you want to learn more about Kumologica, we’d highly recommend you check out this story.
Prerequisites
If you wish to follow the process described in this article, you should install: NPM, Serverless Framework and Kumologica Designer. For detailed instructions how to prepare working environment follow Kumologica documentation.
Getting started
Kumologica Designer allows rapid design, test and deployment of integration flows into AWS Lambda with just few clicks.
We start by running Kumologica Designer. If you have run Designer before, click on the Home button in toolbar. If you are running Designer for the first time, you will be presented with the welcome screen:
Choose Create a new Kumologica project option. You will be presented with New Project screen, enter project name (sampleflow) and choose directory where new project will be created.
Click Create button, Kumologica Designer will open workflow editor with default, very simple hello world api. The flow accepts GET /hello request, logs text message and returns HTTP 200 with payload {“hello”: “world”}
.
Serverless Integration
We keep default flow for simplicity and progress to generating serverless.yml file. Click on CLOUD tab in the right panel (see picture above), and click ellipsis button. You will be presented two options, click on Serverless to generate serverless.yml file. The file contains all information entered in CLOUD tab, including environment variables, memory, timeout values and triggers information. In our example we only have AWS API Gateway details.
Kumologica Designer will open default system editor with serverless.yml file that has been generated.
Deploy
Kumologica Designer generates serverless.yml file in project directory. Open terminal and go to the project directory.
The seamless deployment to AWS Lambda is provided by kumologica-serverless-plugin, it is open sourced and available on Github.
When running deployment for the first time, the kumologica-serverless-plugin must be installed, execute below command in the project directory:
serverless plugin install --name kumologica-serverless-plugin
Once plugin is installed, the sls deploy
command will deploy flow to AWS lambda. The useful parameters to explicitly point region and aws profiles to use are: region
and aws-profile
.
Note that aws-profile
parameter only works if environment variable AWS_PROFILE
is not set. This means, to explicitly specify what profile to use during deploy you need to either:
unset AWS_PROFILE
and specify—-aws-profile
in parameters- export
AWS_PROFILE={YOUR PROFILE}
.
So sls deploy command should look like either:
export AWS_PROFILE={YOUR PROFILE}sls deploy -v --region {YOUR REGION NAME}
or
unset AWS_PROFILEsls deploy -v --aws-profile {YOUR PROFILE NAME} --region {YOUR REGION NAME}
After running deploy command, the output should provide the api gateway endpoint we can use to test hello world api:
Serverless: Stack update finished
...endpoints:GET — https://{API GW ID}.execute-api.{YOUR REGION NAME}.amazonaws.com/dev/hello
Run flow
Testing deployment is as easy as calling the curl command using the endpoint from deploy command output:
curl -X GET https://{API GW ID}.execute-api.{YOUR REGION NAME}.amazonaws.com/dev/hello
and produces output:
{“hello”:”world”}
You can also copy the url into your browser and you should see the same json output.
Conclusion
This article presented Kumologica support of Serverless Framework. We created sample Kumologica flow exposing simple GET /hello api. We deployed Kumologica Flow to AWS Lambda using Serverless Framework with kumologica-serverless-plugin. Lastly we tested api with curl command.
Remember Kumologica is totally free to download and use. Go ahead and give it a try, we would love to hear your feedback.
In the meantime, if there is any specific use case that you would like to see in a future article please let us know in the comments section.