Skip to content

Commit

Permalink
Merge pull request #264 from apex/refactor-examples
Browse files Browse the repository at this point in the history
refactor examples (same behavior in simple examples; less bloated)
  • Loading branch information
tj committed Feb 23, 2016
2 parents 24303c2 + 2ad953d commit 2920e92
Show file tree
Hide file tree
Showing 35 changed files with 53 additions and 165 deletions.
3 changes: 2 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ apex upgrade

Currently supports:

- Nodejs
- Node.js
- Golang
- Python
- Java

## Features

Expand Down
4 changes: 1 addition & 3 deletions _examples/babel-browserify/project.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"name": "babel",
"description": "Node.js Babel example project",
"description": "Node.js Babel (using browserify) example project",
"role": "arn:aws:iam::293503197324:role/lambda",
"runtime": "nodejs",
"handler": "main.default",
"memory": 128,
"timeout": 30,
"hooks": {
"build": "../../node_modules/.bin/browserify -s default -t babelify -o main.js index.js",
"clean": "rm -f main.js"
Expand Down
4 changes: 1 addition & 3 deletions _examples/babel-webpack/project.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"name": "babel",
"description": "Node.js Babel example project",
"description": "Node.js Babel (using webpack) example project",
"role": "arn:aws:iam::293503197324:role/lambda",
"runtime": "nodejs",
"handler": "lib.default",
"memory": 128,
"timeout": 30,
"hooks": {
"build": "../../node_modules/.bin/webpack --config ../../webpack.config.js",
"clean": "rm -fr lib"
Expand Down
4 changes: 0 additions & 4 deletions _examples/go/functions/baz/function.json

This file was deleted.

17 changes: 0 additions & 17 deletions _examples/go/functions/baz/main.go

This file was deleted.

17 changes: 0 additions & 17 deletions _examples/go/functions/foo/main.go

This file was deleted.

1 change: 1 addition & 0 deletions _examples/go/functions/simple/.apexignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ type message struct {

func main() {
apex.HandleFunc(func(event json.RawMessage, ctx *apex.Context) (interface{}, error) {
return &message{"bar"}, nil
var m message

if err := json.Unmarshal(event, &m); err != nil {
return nil, err
}

return m, nil
})
}
3 changes: 0 additions & 3 deletions _examples/go/project.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"name": "go",
"description": "Go example project",
"runtime": "golang",
"memory": 128,
"timeout": 5,
"role": "arn:aws:iam::293503197324:role/lambda"
}
7 changes: 0 additions & 7 deletions _examples/java/functions/bar/function.json

This file was deleted.

7 changes: 0 additions & 7 deletions _examples/java/functions/foo/function.json

This file was deleted.

49 changes: 0 additions & 49 deletions _examples/java/functions/foo/src/main/java/lambda/Hello.java

This file was deleted.

1 change: 1 addition & 0 deletions _examples/java/functions/simple/.apexignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package lambda;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.Context;

public class Main {

Expand All @@ -23,7 +23,6 @@ public ExampleRequest() {
}
}


public static class ExampleResponse {
String hello;

Expand All @@ -44,6 +43,6 @@ public ExampleResponse() {
}

public ExampleResponse handler(ExampleRequest event, Context context) {
return new ExampleResponse("baz");
return new ExampleResponse(event.getHello());
}
}
1 change: 1 addition & 0 deletions _examples/java/functions/with-pom/.apexignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.java
4 changes: 4 additions & 0 deletions _examples/java/functions/with-pom/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"description": "Java example function with existing pom.xml",
"handler": "lambda.Example::handler"
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package lambda;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.Context;

public class Example {

Expand All @@ -23,7 +23,6 @@ public ExampleRequest() {
}
}


public static class ExampleResponse {
String hello;

Expand All @@ -44,6 +43,6 @@ public ExampleResponse() {
}

public ExampleResponse handler(ExampleRequest event, Context context) {
return new ExampleResponse("bar");
return new ExampleResponse(event.getHello());
}
}
2 changes: 0 additions & 2 deletions _examples/java/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"name": "java",
"description": "Java example project",
"memory": 128,
"timeout": 5,
"role": "arn:aws:iam::293503197324:role/lambda"
}
8 changes: 0 additions & 8 deletions _examples/node/functions/bar/function.json

This file was deleted.

6 changes: 0 additions & 6 deletions _examples/node/functions/bar/index.js

This file was deleted.

5 changes: 0 additions & 5 deletions _examples/node/functions/foo/function.json

This file was deleted.

6 changes: 0 additions & 6 deletions _examples/node/functions/foo/index.js

This file was deleted.

5 changes: 5 additions & 0 deletions _examples/node/functions/more-resources/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"description": "Node.js example function with more memory and higher timeout",
"timeout": 10,
"memory": 128
}
6 changes: 6 additions & 0 deletions _examples/node/functions/more-resources/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

console.log('start more-resources')
exports.handle = function(e, ctx) {
console.log('processing event: %j', e)
ctx.succeed({ hello: e.hello })
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

console.log('start baz')
console.log('start simple')
exports.handle = function(e, ctx) {
console.log('processing event: %j', e)
ctx.succeed({ hello: 'baz' })
ctx.succeed({ hello: e.hello })
}
6 changes: 6 additions & 0 deletions _examples/node/functions/using-env/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"description": "Node.js example function using environment variables",
"environment": {
"LOGGLY_TOKEN": "some token defined in function.json"
}
}
9 changes: 9 additions & 0 deletions _examples/node/functions/using-env/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

console.log('start using-env LOGGLY_TOKEN=%s', process.env.LOGGLY_TOKEN)
exports.handle = function(e, ctx) {
console.log('processing event: %j', e)
ctx.succeed({
hello: 'bar',
token_used: process.env.LOGGLY_TOKEN
})
}
4 changes: 1 addition & 3 deletions _examples/node/project.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "node",
"description": "Node.js example project",
"memory": 128,
"timeout": 5,
"role": "arn:aws:iam::293503197324:role/lambda",
"environment": {
"LOGGLY_TOKEN": "123123123123"
"LOGGLY_TOKEN": "some token defined in project.json"
}
}
5 changes: 0 additions & 5 deletions _examples/python/functions/bar/main.py

This file was deleted.

2 changes: 1 addition & 1 deletion _examples/python/functions/dependency/.apexignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
*.dist-info/*
*.dist-info/
1 change: 0 additions & 1 deletion _examples/python/functions/dependency/function.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"name": "dependency",
"description": "Example with python dependency on an external package"
}
5 changes: 0 additions & 5 deletions _examples/python/functions/foo/main.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

print "start baz"
print "start simple function"
def handle(event, context):
print "processing event"
return event
2 changes: 0 additions & 2 deletions _examples/python/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"name": "python",
"description": "Python example project",
"memory": 128,
"timeout": 5,
"role": "arn:aws:iam::293503197324:role/lambda"
}

0 comments on commit 2920e92

Please sign in to comment.