Skip to content

Instantly share code, notes, and snippets.

// Standard AWS λ function
func helloWorld(event *json.RawMessage,
context *sparta.LambdaContext,
w http.ResponseWriter,
logger *logrus.Logger) {
helloWorldCounterMetric.Inc(1)
fmt.Fprint(w, "Hello World")
}
@mweagle
mweagle / main.go
Last active May 3, 2017 01:58
Original source
package main
import (
"fmt"
"os"
sparta "github.com/mweagle/Sparta"
"github.com/mweagle/SpartaPython"
"github.com/mweagle/Sparta/cgo"
@mweagle
mweagle / main.go
Last active May 3, 2017 01:57
After transformation
package main
// #include <stdio.h>
// #include <stdlib.h>
// #include <string.h>
// #include <stdio.h>
import "C"
import "github.com/aws/aws-sdk-go/aws/credentials"
import (
@mweagle
mweagle / shim.py
Created May 3, 2017 02:00
Python core shim
bytesWritten = lib.Lambda(funcName.encode(‘utf-8’),
json.dumps(request).encode(‘utf-8’),
credentials.access_key.encode(‘utf-8’),
credentials.secret_key.encode(‘utf-8’),
credentials.token.encode(‘utf-8’),
byref(exitCode),
response_content_type_buffer,
MAX_RESPONSE_CONTENT_TYPE_SIZE-1,
response_buffer,
MAX_RESPONSE_SIZE-1)
@mweagle
mweagle / mock_http.go
Created May 3, 2017 02:02
mock request
// Create an http.Request object with this data...
spartaResp := newSpartaMockHTTPResponse()
spartaReq := &http.Request{
Method: "POST",
URL: &url.URL{
Scheme: "http",
Path: fmt.Sprintf("/%s", functionName),
},
Proto: "HTTP/1.1",
ProtoMajor: 1,
@mweagle
mweagle / include.go
Created May 3, 2017 02:08
import header
import (
spartaCGO “github.com/mweagle/Sparta/cgo”
)
func init() {
sparta.RegisterCodePipelineEnvironment("test", map[string]string{
"MESSAGE": "Hello Test!",
})
sparta.RegisterCodePipelineEnvironment("production", map[string]string{
"MESSAGE": "Hello Production!",
})
}
// Standard http.HandlerFunc() that will be run as a lambda function
func helloSpartaWorld(w http.ResponseWriter, r *http.Request) {
messageText := os.Getenv("MESSAGE")
if "" == messageText {
messageText = "$MESSAGE not defined"
}
fmt.Fprint(w, messageText)
}
func helloSpartaWorld(w http.ResponseWriter, r *http.Request) {
...
}
loggerVal, loggerValOk := r.Context().Value(sparta.ContextKeyLogger).(*logrus.Logger)