Quickly publish serverless applications in the cloud.
npm install panda-sky_Quicky publish severless APIs to AWS._
panda-sky as a global package, granting you access to the skynpm install -g panda-sky
Make sure you have an AWS account, and that you store your credentials at~/.aws/credentials.
> If you don't have an Amazon Web Services (AWS) account currently, stop here,
go signup and get CLI access credentials
and then come back here.
mkdir hello-sky && cd hello-sky
npm init
sky init
sky build
sky publish staging
In about 60 seconds, you will see a message like this:
> Your API is online and ready at the following endpoint:
> https://
If you direct your browser to
https://
see the test message from the API you just deployed. Adding your name to the
URL path will change the page, a simple demonstration dynamic behavior.
You can also view a description of the API by directing a request against the API
root, https://
mkdir greeting-api && cd greeting-api
npm init
sky init
Panda Sky needs a package.json to anchor your project's dependencies when it gathers them and sends them to AWS to be used within a Lambda. sky init gives you the starter files for a project.
Edit your api.yaml. This file is the authoritative description of your API. Panda Sky uses it to build an API within the API Gateway platform. Each method is mapped to a corresponding Lambda that gets invoked when the method's handler recieves an HTTP request.
``yaml
resources:
greeting:
path: "/greeting/{name}"
description: Returns a greeting for {name}.
methods:
get:
method: GET
signature:
status: 200
accept: text/html
`
Add a JavaScript file under src/sky.js:
Lambdas execute Javascript code compatible with Node 6.10. Lambdas accept context
from the corresponding Gateway method's HTTP request. After executing arbitrary
code, the result is returned in the callback and sent as the response in the
Gateway method.
The code snippet below shows a section of the template code sky init dropsGET
into your repo. This method is invoked when the method is used in agreeting
request against the resource. Edits here affect the API's response.
`javascript${fullName}-greeting-get
API[] = async( function*(data, context, callback) {
var message, name;
name = data.name || "World";
message =
;
message += "Seeing this page indicates a successful deployment of your test API with Panda Sky!
";
return callback(null, message);
});
`$3
Panda Sky supports the injection of environmental variables into your Lambda's context. These can be accessed from the process Node variable.> Currently within api.yaml, however this may be moved into sky.yaml so they can be set on a per-environment basis.
`yaml
variables:
foobar: This optional value is injected into the Lambda context
`
> sky.js
`javascript
var {foobar} = process.env;
` Built-in Helpers
Panda Sky comes with helpers to ease development within a Lambda environment:
`coffeescript
Import Panda Sky Helpers
{response, s3} = require "panda-sky-helpers"
`$3
- s3 is a wrapper around the AWS SDK library for S3.`coffeescript
{get, put, del} = s3 BucketName
data = yield get "foobar.yaml"
`The
get, put, and del methods do what they say. They are promises you can either chain .then or use ES6's yield / generator construct with. They are very thin wrappers, either succeeding or returning an error directly from the AWS library.$3
To invoke a given response within a Lambda, use the response class from Panda Sky
`coffeescript
Import Panda Sky Helpers
{response} = require "panda-sky"
new response.NotFound("Unable to locate the blog post in the database")
new response.Unauthorized("You must login to access this resource")
new response.ServiceUnavailable("Try again in 30 minutes")
`It takes the form:
`
new response.()
`> Note that responses must be explicitly definied within the API description.
Custom Domains
In order to publish your API to production, you need a domain to publish it to.
[You need to tell AWS about it and acquire an SSL (TLS) cert][domain-setup].
[domain-setup]:https://www.pandastrike.com/open-source/haiku9/publish/aws-setup
$3
Add the name of your API and the domain to your
sky.yaml file:This file tracks the overall configuration for your app. Panda Sky divides
configuration between "environments" to group related config within one cli
target. It allows you to switch your environment target without repeatedly
editing this file.
The
cache stanza holds configuration for CloudFront distributions, which
provides both edge caching for your API responses and custom domain assignment.
Please note that setting up a distribution is time-intensive. It can take 15-30
minutes to setup and sync your allocation across AWS's global constellation of
edge servers.`yaml
name: greeting
description: Greeting API
aws:
runtime: nodejs6.10
domain:
- greeting.com
region: us-west-2
environments: staging:
hostnames:
- staging-api
production:
hostnames:
- api
cache:
expires: 1800
priceClass: 100
``Publish your lambdas and their associated Gateway.
sky publish staging
Your environment's custom domain is treated as a
seperate resource. Publishing it will take a while
(~30 minutes), but Sky (and AWS) are doing a
lot for you. In addition to a custom domain with
TLS termination, CloudFront is synchronizing
an edge cache among servers deployed across
the planet.
curl https://staging-api.greeting.com/greeting/Ace
Hello, Ace!
Panda Sky is in beta.