apex

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2015 License: MIT Imports: 5 Imported by: 0

README

Apex

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, Ruby, and others out of the box.

Installation

Download binaries or:

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

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 "package.json" with the function name a configuration:

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

Create and deploy the function:

$ apex deploy

Create a file with a sample request "request.js":

{
  "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"}
...

Environment variables

Currently the following environment variables are used:

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

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 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