apex

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 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
  • Binary install (useful for continuous deployment in CI etc)
  • Command-line function invocation with JSON streams
  • Transparently generates a zip for your deploy

Example

This example shows how you can use Apex to launch a simple Node.js echo function.

First create the function implementation in "index.js":

exports.handle = function(e, ctx) {
  ctx.succeed(e)
}

Next create a "lambda.json" with the function name a configuration:

{
  "name": "echo",
  "description": "Echo request example",
  "runtime": "nodejs",
  "memory": 128,
  "timeout": 5
}

Deploy the function:

$ apex deploy

Create a file with a sample request in "request.json":

{
  "event": {
    "hello": "world"
  },
  "context": {
    "user": "Tobi"
  }
}

Test out your new function:

$ apex invoke < request.json
{"hello":"world"}

Streaming input

The invoke sub-command allows you to stream input over stdin:

$ apex invoke < request.json

This not only works for single requests, but for multiple, as shown in the following example using phony(1):

$ echo -n '{ "event": { "user": "{{name}}" } }' | phony | apex invoke
{"user":"Delmer Malone"}
{"user":"Jc Reeves"}
{"user":"Luna Fletcher"}
...

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)

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
go
cmd
Package function implements higher-level functionality for dealing with Lambda functions.
Package function implements higher-level functionality for dealing with Lambda functions.
Package kinesis provides structs for working with AWS Kinesis records.
Package kinesis provides structs for working with AWS Kinesis records.
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