apex

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 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

$ go get github.com/apex/apex/cmd/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"}

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

Shimming

Apex uses a Node.js shim for non-native language support. Because of this you must use stderr for logging, as stdout is used for the reply JSON.

FAQ

How do you manage multiple environments?

It's highly recommended to create separate AWS accounts for staging and production environments. This provides complete isolation of resources, and allows you to easily provide granular access to environments as required.

How do you structure projects with multiple Lambda functions?

Since apex(1) is function-oriented, you can structure projects however you like. You may use a single repository with multiple functions, or a repository per function. Use the -C flag to invoke commands against a specific function's directory.

How is this different than serverless.com?

The Serverless implementation is written in Node.js, and has a larger scope than Apex. If you're looking for full project management Serverless may be a better option for you!

Serverless uses CloudFormation to bootstrap resources, which can be great for getting started, but less robust than Terraform for managing infrastructure throughout its lifetime. For this reason Apex does not currently provide resource management.

At the time of writting Serverless does not support shimming for languages which are not supported natively by Lambda, such as Golang. Apex does this for you out of the box.

License

MIT

Documentation

Overview

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

Index

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.

Jump to

Keyboard shortcuts

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