apex

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2016 License: MIT Imports: 6 Imported by: 0

README

Build Status Apex Serverless Architecture

Apex is a small tool for deploying and managing AWS Lambda functions. With shims for languages not yet supported by Lambda, you can use Golang out of the box.

Installation

Download binaries or:

$ go get github.com/apex/apex/cmd/apex

Runtimes

Currently supports:

  • Nodejs
  • Golang
  • Python

Features

  • Supports languages Lambda does not natively support via shim, such as Go
  • Binary install (useful for continuous deployment in CI etc)
  • Project level function and resource management
  • Command-line function invocation with JSON streams
  • Transparently generates a zip for your deploy
  • Function rollback support
  • Tail function CloudWatchLogs
  • Concurrency for quick deploys

Example

Apex projects are made up of a project.json configuration file, and zero or more Lambda functions defined in the "functions" directory. Here's an example file structure:

functions
├── bar
│   ├── function.json
│   └── index.js
├── baz
│   ├── function.json
│   └── index.js
└── foo
    ├── function.json
    └── index.js
project.json

The project.json file defines project level configuration that applies to all functions, and defines dependencies. For this simple example the following will do:

{
  "name": "example",
  "description": "Example project"
}

Each function uses a function.json configuration file to define function-specific properties such as the runtime, amount of memory allocated, and timeout. For example:

{
  "name": "bar",
  "description": "Node.js example function",
  "runtime": "nodejs",
  "memory": 128,
  "timeout": 5,
  "role": "arn:aws:iam::293503197324:role/lambda"
}

Finally the source for the functions themselves look like this in Node.js:

console.log('start bar')
exports.handle = function(e, ctx) {
  ctx.succeed({ hello: 'bar' })
}

Or using the Golang Lambda package, Apex supports Golang out of the box with a Node.js shim:

package main

import (
  "encoding/json"

  "github.com/apex/apex"
)

type Message struct {
  Hello string `json:"hello"`
}

func main() {
  apex.HandleFunc(func(event json.RawMessage, ctx *apex.Context) (interface{}, error) {
    return &Message{"baz"}, nil
  })
}

Apex operates at the project level, but many commands allow you to specify specific functions. For example you may deploy the entire project with a single command:

$ apex deploy

Or whitelist functions to deploy:

$ apex deploy foo bar

Credentials

Via environment variables:

  • AWS_ACCESS_KEY AWS account access key
  • AWS_SECRET_KEY AWS account secret key
  • AWS_REGION AWS region

Via ~/.aws configuration:

  • AWS_PROFILE profile name to use
  • AWS_REGION AWS region (aws-sdk-go does not read ~/.aws/config)

Contributors

License

MIT

Documentation

Overview

Package apex provides Lambda support for Go via a Node.js shim and this package for operating over stdio.

Example
package main

import (
	"encoding/json"

	"github.com/apex/apex"
)

type Message struct {
	Hello string `json:"hello"`
}

func main() {
	apex.HandleFunc(func(event json.RawMessage, ctx *apex.Context) (interface{}, error) {
		return &Message{"world"}, nil
	})
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handle

func Handle(h Handler)

Handle Lambda events with the given handler.

func HandleFunc

func HandleFunc(h HandlerFunc)

HandleFunc handles Lambda events with the given handler function.

Types

type Context

type Context struct {
	InvokeID                 string          `json:"invokeid"`
	RequestID                string          `json:"awsRequestId"`
	FunctionName             string          `json:"functionName"`
	FunctionVersion          string          `json:"functionVersion"`
	LogGroupName             string          `json:"logGroupName"`
	LogStreamName            string          `json:"logStreamName"`
	MemoryLimitInMB          string          `json:"memoryLimitInMB"`
	IsDefaultFunctionVersion bool            `json:"isDefaultFunctionVersion"`
	ClientContext            json.RawMessage `json:"clientContext"`
}

Context represents the context data provided by a Lambda invocation.

type Handler

type Handler interface {
	Handle(json.RawMessage, *Context) (interface{}, error)
}

Handler handles Lambda events.

type HandlerFunc

type HandlerFunc func(json.RawMessage, *Context) (interface{}, error)

HandlerFunc implements Handler.

func (HandlerFunc) Handle

func (h HandlerFunc) Handle(event json.RawMessage, ctx *Context) (interface{}, error)

Handle Lambda event.

Directories

Path Synopsis
_examples
cmd
Package function implements function-level operations.
Package function implements function-level operations.
Package kinesis provides structs for working with AWS Kinesis records.
Package kinesis provides structs for working with AWS Kinesis records.
Package logs implements AWS CloudWatchLogs tailing.
Package logs implements AWS CloudWatchLogs tailing.
Package project implements multi-function operations.
Package project implements multi-function operations.
Package runtime provides interfaces for defining Lambda runtimes and appropriate shims for arbitrary language support.
Package runtime provides interfaces for defining Lambda runtimes and appropriate shims for arbitrary language support.
Package shim provides a shim for running arbitrary languages on Lambda.
Package shim provides a shim for running arbitrary languages on Lambda.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL