Update app and tooling

This commit is contained in:
Lawrence Chen 2026-01-29 17:36:26 -08:00
parent 3046531bdd
commit e620ec7349
4950 changed files with 2975120 additions and 10 deletions

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = require("node:path");
const node_child_process_1 = require("node:child_process");
// Delegate out to the provided `executable` file within the lambda
const executable = (0, node_path_1.join)(process.env.LAMBDA_TASK_ROOT, 'executable');
(0, node_child_process_1.spawn)(executable, [], { stdio: 'inherit' });
//# sourceMappingURL=bootstrap.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../../src/runtimes/executable/bootstrap.ts"],"names":[],"mappings":";;AAAA,yCAAiC;AACjC,2DAA2C;AAE3C,mEAAmE;AACnE,MAAM,UAAU,GAAG,IAAA,gBAAI,EAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;AACpE,IAAA,0BAAK,EAAC,UAAU,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC"}

View file

@ -0,0 +1,3 @@
#!/bin/bash
# Delegate out to the provided `executable` file
exec "$LAMBDA_TASK_ROOT/executable" "$@"

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,273 @@
// Credits:
// https://github.com/lambci/docker-lambda/blob/f6b4765a9b659ceb949c34b19390026820ddd462/go1.x/run/aws-lambda-mock.go
// https://binx.io/blog/2018/12/03/aws-lambda-custom-bootstrap-in-go
package main
import (
"bytes"
"encoding/hex"
"fmt"
"github.com/aws/aws-lambda-go/lambda/messages"
"github.com/phayes/freeport"
"io/ioutil"
"log"
"math/rand"
"net"
"net/http"
"net/rpc"
"os"
"os/exec"
"os/signal"
"path"
"reflect"
"strconv"
"syscall"
"time"
)
func main() {
rand.Seed(time.Now().UTC().UnixNano())
mockContext := &MockLambdaContext{
FnName: getEnv("AWS_LAMBDA_FUNCTION_NAME", "test"),
Handler: getEnv("AWS_LAMBDA_FUNCTION_HANDLER", getEnv("_HANDLER", "handler")),
Version: getEnv("AWS_LAMBDA_FUNCTION_VERSION", "$LATEST"),
MemSize: getEnv("AWS_LAMBDA_FUNCTION_MEMORY_SIZE", "1536"),
Timeout: getEnv("AWS_LAMBDA_FUNCTION_TIMEOUT", "300"),
Region: getEnv("AWS_REGION", getEnv("AWS_DEFAULT_REGION", "us-east-1")),
AccountId: getEnv("AWS_ACCOUNT_ID", strconv.FormatInt(int64(rand.Int31()), 10)),
Start: time.Now(),
Pid: 1,
}
mockContext.ParseTimeout()
awsAccessKey := getEnv("AWS_ACCESS_KEY", getEnv("AWS_ACCESS_KEY_ID", "SOME_ACCESS_KEY_ID"))
awsSecretKey := getEnv("AWS_SECRET_KEY", getEnv("AWS_SECRET_ACCESS_KEY", "SOME_SECRET_ACCESS_KEY"))
awsSessionToken := getEnv("AWS_SESSION_TOKEN", os.Getenv("AWS_SECURITY_TOKEN"))
taskRoot := getEnv("LAMBDA_TASK_ROOT", "/var/task")
handlerPath := path.Join(taskRoot, mockContext.Handler)
os.Setenv("AWS_LAMBDA_FUNCTION_NAME", mockContext.FnName)
os.Setenv("AWS_LAMBDA_FUNCTION_VERSION", mockContext.Version)
os.Setenv("AWS_LAMBDA_FUNCTION_MEMORY_SIZE", mockContext.MemSize)
os.Setenv("AWS_LAMBDA_LOG_GROUP_NAME", "/aws/lambda/"+mockContext.FnName)
os.Setenv("AWS_LAMBDA_LOG_STREAM_NAME", logStreamName(mockContext.Version))
os.Setenv("AWS_REGION", mockContext.Region)
os.Setenv("AWS_DEFAULT_REGION", mockContext.Region)
os.Setenv("_HANDLER", mockContext.Handler)
port, err := freeport.GetFreePort()
if err != nil {
log.Fatal(fmt.Errorf("Freeport Error %s", err))
}
portStr := strconv.Itoa(port)
var cmd *exec.Cmd
cmd = exec.Command(handlerPath)
cmd.Env = append(os.Environ(),
"_LAMBDA_SERVER_PORT="+portStr,
"AWS_ACCESS_KEY="+awsAccessKey,
"AWS_ACCESS_KEY_ID="+awsAccessKey,
"AWS_SECRET_KEY="+awsSecretKey,
"AWS_SECRET_ACCESS_KEY="+awsSecretKey,
)
if len(awsSessionToken) > 0 {
cmd.Env = append(cmd.Env,
"AWS_SESSION_TOKEN="+awsSessionToken,
"AWS_SECURITY_TOKEN="+awsSessionToken,
)
}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
if err = cmd.Start(); err != nil {
defer abortRequest(mockContext, err)
return
}
mockContext.Pid = cmd.Process.Pid
p, _ := os.FindProcess(-mockContext.Pid)
defer p.Signal(syscall.SIGKILL)
// Terminate the child process upon SIGINT / SIGTERM
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
p, _ := os.FindProcess(-mockContext.Pid)
p.Signal(syscall.SIGKILL)
os.Exit(0)
}()
var conn net.Conn
for {
conn, err = net.Dial("tcp", ":"+portStr)
if mockContext.HasExpired() {
defer abortRequest(mockContext, mockContext.TimeoutErr())
return
}
if err == nil {
break
}
if oerr, ok := err.(*net.OpError); ok {
// Connection refused, try again
if oerr.Op == "dial" && oerr.Net == "tcp" {
time.Sleep(5 * time.Millisecond)
continue
}
}
defer abortRequest(mockContext, err)
return
}
mockContext.Rpc = rpc.NewClient(conn)
for {
err = mockContext.Rpc.Call("Function.Ping", messages.PingRequest{}, &messages.PingResponse{})
if mockContext.HasExpired() {
defer abortRequest(mockContext, mockContext.TimeoutErr())
return
}
if err == nil {
break
}
time.Sleep(5 * time.Millisecond)
}
// XXX: The Go runtime seems to amortize the startup time, reset it here
mockContext.Start = time.Now()
// If we got to here then the handler process has initialized successfully
mockContext.ProcessEvents()
}
func abortRequest(mockContext *MockLambdaContext, err error) {
log.Fatal(err)
}
func getEnv(key, fallback string) string {
value := os.Getenv(key)
if value != "" {
return value
}
return fallback
}
func logStreamName(version string) string {
randBuf := make([]byte, 16)
rand.Read(randBuf)
hexBuf := make([]byte, hex.EncodedLen(len(randBuf)))
hex.Encode(hexBuf, randBuf)
return time.Now().Format("2006/01/02") + "/[" + version + "]" + string(hexBuf)
}
func getErrorType(err interface{}) string {
if errorType := reflect.TypeOf(err); errorType.Kind() == reflect.Ptr {
return errorType.Elem().Name()
} else {
return errorType.Name()
}
}
type LambdaError struct {
Message string `json:"errorMessage"`
Type string `json:"errorType,omitempty"`
StackTrace []*messages.InvokeResponse_Error_StackFrame `json:"stackTrace,omitempty"`
}
type MockLambdaContext struct {
Pid int
FnName string
Handler string
Version string
MemSize string
Timeout string
Region string
AccountId string
Start time.Time
TimeoutDuration time.Duration
Reply *messages.InvokeResponse
Rpc *rpc.Client
}
func (mc *MockLambdaContext) ProcessEvents() {
awsLambdaRuntimeApi := os.Getenv("AWS_LAMBDA_RUNTIME_API")
if awsLambdaRuntimeApi == "" {
panic("Missing: 'AWS_LAMBDA_RUNTIME_API'")
}
for {
// get the next event
requestUrl := fmt.Sprintf("http://%s/2018-06-01/runtime/invocation/next", awsLambdaRuntimeApi)
resp, err := http.Get(requestUrl)
if err != nil {
log.Fatal(fmt.Errorf("Error getting next invocation: %v", err))
}
requestId := resp.Header.Get("Lambda-Runtime-Aws-Request-Id")
eventData, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(fmt.Errorf("Error reading body: %s", err))
}
err = mc.Rpc.Call("Function.Invoke", mc.Request(requestId, eventData), &mc.Reply)
if err != nil {
log.Fatal(fmt.Errorf("Error invoking RPC call: %s", err))
}
responseUrl := fmt.Sprintf("http://%s/2018-06-01/runtime/invocation/%s/response", awsLambdaRuntimeApi, requestId)
req, err := http.NewRequest("POST", responseUrl, bytes.NewBuffer(mc.Reply.Payload))
if err != nil {
log.Fatal(fmt.Errorf("Error creating response HTTP request: %s", err))
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
client.Timeout = 0
_, err = client.Do(req)
if err != nil {
log.Fatal(fmt.Errorf("Error sending response: %s", err))
}
}
}
func (mc *MockLambdaContext) ParseTimeout() {
timeoutDuration, err := time.ParseDuration(mc.Timeout + "s")
if err != nil {
panic(err)
}
mc.TimeoutDuration = timeoutDuration
}
func (mc *MockLambdaContext) Deadline() time.Time {
return mc.Start.Add(mc.TimeoutDuration)
}
func (mc *MockLambdaContext) HasExpired() bool {
return time.Now().After(mc.Deadline())
}
func (mc *MockLambdaContext) Request(requestId string, payload []byte) *messages.InvokeRequest {
return &messages.InvokeRequest{
Payload: payload,
RequestId: requestId,
XAmznTraceId: getEnv("_X_AMZN_TRACE_ID", ""),
InvokedFunctionArn: getEnv("AWS_LAMBDA_FUNCTION_INVOKED_ARN", ""),
Deadline: messages.InvokeRequest_Timestamp{
Seconds: mc.Deadline().Unix(),
Nanos: int64(mc.Deadline().Nanosecond()),
},
}
}
func (mc *MockLambdaContext) TimeoutErr() error {
return fmt.Errorf("%s %s Task timed out after %s.00 seconds", time.Now().Format("2006-01-02T15:04:05.999Z"),
"1234", mc.Timeout)
}

View file

@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = require("node:path");
const node_child_process_1 = require("node:child_process");
const filename_1 = require("./filename");
const out = (0, filename_1.getOutputFile)();
const bootstrap = (0, node_path_1.join)(__dirname, out);
(0, node_child_process_1.spawn)(bootstrap, [], { stdio: 'inherit' });
//# sourceMappingURL=bootstrap.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../../src/runtimes/go1.x/bootstrap.ts"],"names":[],"mappings":";;AAAA,yCAAiC;AACjC,2DAA2C;AAC3C,yCAA2C;AAE3C,MAAM,GAAG,GAAG,IAAA,wBAAa,GAAE,CAAC;AAC5B,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AACvC,IAAA,0BAAK,EAAC,SAAS,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC"}

View file

@ -0,0 +1 @@
export declare function getOutputFile(): string;

View file

@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOutputFile = void 0;
function getOutputFile() {
const ext = process.platform === 'win32' ? '.exe' : '';
return `bootstrap${ext}`;
}
exports.getOutputFile = getOutputFile;
//# sourceMappingURL=filename.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"filename.js","sourceRoot":"","sources":["../../../../src/runtimes/go1.x/filename.ts"],"names":[],"mappings":";;;AAAA,SAAgB,aAAa;IAC5B,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACvD,OAAO,YAAY,GAAG,EAAE,CAAC;AAC1B,CAAC;AAHD,sCAGC"}

View file

@ -0,0 +1,2 @@
import { Runtime } from '../../types';
export declare function init({ cacheDir }: Runtime): Promise<void>;

View file

@ -0,0 +1,57 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
const node_path_1 = require("node:path");
const tinyexec_1 = require("tinyexec");
const debug_1 = __importDefault(require("debug"));
const promises_1 = require("node:fs/promises");
const filename_1 = require("./filename");
const debug = (0, debug_1.default)('@vercel/fun:runtimes/go1.x');
function _go(opts) {
return function go(...args) {
debug('Exec %o', `go ${args.join(' ')}`);
return (0, tinyexec_1.exec)('go', args, Object.assign({ stdio: 'inherit' }, opts));
};
}
function init({ cacheDir }) {
return __awaiter(this, void 0, void 0, function* () {
const source = (0, node_path_1.join)(cacheDir, 'bootstrap.go');
const out = (0, filename_1.getOutputFile)();
let data = yield (0, promises_1.readFile)(source, 'utf8');
// Fix windows
if (process.platform === 'win32') {
debug('detected windows, so stripping Setpgid');
data = data
.split('\n')
.filter(line => !line.includes('Setpgid'))
.join('\n');
}
// Prepare a temporary `$GOPATH`
const GOPATH = (0, node_path_1.join)(cacheDir, 'go');
// The source code must reside in `$GOPATH/src` for `go get` to work
const bootstrapDir = (0, node_path_1.join)(GOPATH, 'src', out);
yield (0, promises_1.mkdir)(bootstrapDir, { recursive: true });
yield (0, promises_1.writeFile)((0, node_path_1.join)(bootstrapDir, 'bootstrap.go'), data);
const go = _go({ cwd: bootstrapDir, env: Object.assign(Object.assign({}, process.env), { GOPATH }) });
const bootstrap = (0, node_path_1.join)(cacheDir, out);
debug('Compiling Go runtime binary %o -> %o', source, bootstrap);
yield go('get');
yield go('build', '-o', bootstrap, 'bootstrap.go');
// Clean up `$GOPATH` from the cacheDir
yield (0, promises_1.rm)(GOPATH, { recursive: true });
});
}
exports.init = init;
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtimes/go1.x/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yCAAiC;AACjC,uCAAgC;AAChC,kDAAgC;AAEhC,+CAA4E;AAC5E,yCAA2C;AAE3C,MAAM,KAAK,GAAG,IAAA,eAAW,EAAC,4BAA4B,CAAC,CAAC;AAExD,SAAS,GAAG,CAAC,IAAI;IAChB,OAAO,SAAS,EAAE,CAAC,GAAG,IAAI;QACzB,KAAK,CAAC,SAAS,EAAE,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACzC,OAAO,IAAA,eAAI,EAAC,IAAI,EAAE,IAAI,kBAAI,KAAK,EAAE,SAAS,IAAK,IAAI,EAAG,CAAC;IACxD,CAAC,CAAC;AACH,CAAC;AAED,SAAsB,IAAI,CAAC,EAAE,QAAQ,EAAW;;QAC/C,MAAM,MAAM,GAAG,IAAA,gBAAI,EAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QAC9C,MAAM,GAAG,GAAG,IAAA,wBAAa,GAAE,CAAC;QAC5B,IAAI,IAAI,GAAG,MAAM,IAAA,mBAAQ,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAE1C,cAAc;QACd,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;YACjC,KAAK,CAAC,wCAAwC,CAAC,CAAC;YAChD,IAAI,GAAG,IAAI;iBACT,KAAK,CAAC,IAAI,CAAC;iBACX,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;iBACzC,IAAI,CAAC,IAAI,CAAC,CAAC;SACb;QAED,gCAAgC;QAChC,MAAM,MAAM,GAAG,IAAA,gBAAI,EAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAEpC,oEAAoE;QACpE,MAAM,YAAY,GAAG,IAAA,gBAAI,EAAC,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;QAC9C,MAAM,IAAA,gBAAK,EAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/C,MAAM,IAAA,oBAAS,EAAC,IAAA,gBAAI,EAAC,YAAY,EAAE,cAAc,CAAC,EAAE,IAAI,CAAC,CAAC;QAE1D,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,YAAY,EAAE,GAAG,kCAAO,OAAO,CAAC,GAAG,KAAE,MAAM,GAAE,EAAE,CAAC,CAAC;QACvE,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACtC,KAAK,CAAC,sCAAsC,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QACjE,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC;QAChB,MAAM,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC;QAEnD,uCAAuC;QACvC,MAAM,IAAA,aAAM,EAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,CAAC;CAAA;AA9BD,oBA8BC"}

16
node_modules/@vercel/fun/dist/src/runtimes/nodejs/bootstrap generated vendored Executable file
View file

@ -0,0 +1,16 @@
#!/bin/sh
set -eu
# Credit: https://github.com/lambci/node-custom-lambda/blob/master/v10.x/bootstrap
# `NODE_PATH` is *not* a restricted env var, so only set the
# default one if the user did not provide one of their own
if [ -z "${NODE_PATH-}" ]; then
export NODE_PATH="/opt/nodejs/node8/node_modules:/opt/nodejs/node_modules:${LAMBDA_RUNTIME_DIR}/node_modules:${LAMBDA_RUNTIME_DIR}:${LAMBDA_TASK_ROOT}"
fi
exec node \
--expose-gc \
--max-semi-space-size=$((AWS_LAMBDA_FUNCTION_MEMORY_SIZE * 5 / 100)) \
--max-old-space-size=$((AWS_LAMBDA_FUNCTION_MEMORY_SIZE * 90 / 100)) \
"$LAMBDA_RUNTIME_DIR/bootstrap.js"

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,204 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Credit: https://github.com/lambci/node-custom-lambda/blob/master/v10.x/bootstrap.js
*/
const http_1 = __importDefault(require("http"));
const RUNTIME_PATH = '/2018-06-01/runtime';
const { AWS_LAMBDA_FUNCTION_NAME, AWS_LAMBDA_FUNCTION_VERSION, AWS_LAMBDA_FUNCTION_MEMORY_SIZE, AWS_LAMBDA_LOG_GROUP_NAME, AWS_LAMBDA_LOG_STREAM_NAME, LAMBDA_TASK_ROOT, _HANDLER, AWS_LAMBDA_RUNTIME_API } = process.env;
delete process.env.SHLVL;
const [HOST, PORT] = AWS_LAMBDA_RUNTIME_API.split(':');
start();
// Simple `util.promisify()` polyfill for Node 6.x
function promisify(fn) {
return function (...args) {
return new Promise((resolve, reject) => {
args.push((err, result) => {
if (err)
return reject(err);
resolve(result);
});
const r = fn.apply(this, args);
if (typeof r !== 'undefined') {
resolve(r);
}
});
};
}
function start() {
return __awaiter(this, void 0, void 0, function* () {
let handler;
try {
handler = getHandler();
}
catch (e) {
yield initError(e);
return process.exit(1);
}
try {
yield processEvents(handler);
}
catch (e) {
console.error(e);
return process.exit(1);
}
});
}
function processEvents(handler) {
return __awaiter(this, void 0, void 0, function* () {
while (true) {
const { event, context } = yield nextInvocation();
let result;
try {
result = yield handler(event, context);
}
catch (e) {
yield invokeError(e, context);
continue;
}
yield invokeResponse(result, context);
}
});
}
function initError(err) {
return __awaiter(this, void 0, void 0, function* () {
return postError(`${RUNTIME_PATH}/init/error`, err);
});
}
function nextInvocation() {
return __awaiter(this, void 0, void 0, function* () {
const res = yield request({ path: `${RUNTIME_PATH}/invocation/next` });
if (res.statusCode !== 200) {
throw new Error(`Unexpected /invocation/next response: ${JSON.stringify(res)}`);
}
if (res.headers['lambda-runtime-trace-id']) {
process.env._X_AMZN_TRACE_ID = res.headers['lambda-runtime-trace-id'];
}
else {
delete process.env._X_AMZN_TRACE_ID;
}
const deadlineMs = Number(res.headers['lambda-runtime-deadline-ms']);
const awsRequestId = res.headers['lambda-runtime-aws-request-id'];
const context = {
callbackWaitsForEmptyEventLoop: false,
logGroupName: AWS_LAMBDA_LOG_GROUP_NAME,
logStreamName: AWS_LAMBDA_LOG_STREAM_NAME,
functionName: AWS_LAMBDA_FUNCTION_NAME,
memoryLimitInMB: AWS_LAMBDA_FUNCTION_MEMORY_SIZE,
functionVersion: AWS_LAMBDA_FUNCTION_VERSION,
invokeid: awsRequestId,
awsRequestId,
invokedFunctionArn: res.headers['lambda-runtime-invoked-function-arn'],
getRemainingTimeInMillis: () => deadlineMs - Date.now()
};
if (res.headers['lambda-runtime-client-context']) {
context.clientContext = JSON.parse(res.headers['lambda-runtime-client-context']);
}
if (res.headers['lambda-runtime-cognito-identity']) {
context.identity = JSON.parse(res.headers['lambda-runtime-cognito-identity']);
}
const event = JSON.parse(res.body);
return { event, context };
});
}
function invokeResponse(result, context) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield request({
method: 'POST',
path: `${RUNTIME_PATH}/invocation/${context.awsRequestId}/response`,
body: JSON.stringify(result)
});
if (res.statusCode !== 202) {
throw new Error(`Unexpected /invocation/response response: ${JSON.stringify(res)}`);
}
});
}
function invokeError(err, context) {
return __awaiter(this, void 0, void 0, function* () {
return postError(`${RUNTIME_PATH}/invocation/${context.awsRequestId}/error`, err);
});
}
function postError(path, err) {
return __awaiter(this, void 0, void 0, function* () {
const lambdaErr = toLambdaErr(err);
const res = yield request({
method: 'POST',
path,
headers: {
'Content-Type': 'application/json',
'Lambda-Runtime-Function-Error-Type': lambdaErr.errorType
},
body: JSON.stringify(lambdaErr)
});
if (res.statusCode !== 202) {
throw new Error(`Unexpected ${path} response: ${JSON.stringify(res)}`);
}
});
}
function getHandler() {
const segments = _HANDLER.split('/');
const appParts = segments[segments.length - 1].split('.');
if (appParts.length !== 2) {
throw new Error(`Bad handler ${_HANDLER}`);
}
const [moduleFile, handlerName] = appParts;
const modulePath = [...segments.slice(0, -1), moduleFile].join('/');
let app;
try {
app = require(`${LAMBDA_TASK_ROOT}/${modulePath}`);
}
catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
throw new Error(`Unable to import module '${modulePath}'`);
}
throw e;
}
const userHandler = app[handlerName];
if (userHandler == null) {
throw new Error(`Handler '${handlerName}' missing on module '${modulePath}'`);
}
else if (typeof userHandler !== 'function') {
throw new Error(`Handler '${handlerName}' from '${modulePath}' is not a function`);
}
return userHandler.length >= 3 ? promisify(userHandler) : userHandler;
}
function request(options) {
return __awaiter(this, void 0, void 0, function* () {
options.host = HOST;
options.port = PORT;
return new Promise((resolve, reject) => {
const req = http_1.default.request(options, res => {
const bufs = [];
res.on('data', data => bufs.push(data));
res.on('end', () => resolve({
statusCode: res.statusCode,
headers: res.headers,
body: Buffer.concat(bufs).toString('utf8')
}));
res.on('error', reject);
});
req.on('error', reject);
req.end(options.body);
});
});
}
function toLambdaErr({ name, message, stack }) {
return {
errorType: name,
errorMessage: message,
stackTrace: (stack || '').split('\n').slice(1)
};
}
//# sourceMappingURL=bootstrap.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,9 @@
#!/bin/sh
set -eu
# Ensure the downloaded Node.js version is used
export PATH="$LAMBDA_RUNTIME_DIR/bin:$PATH"
# Execute the "nodejs" runtime bootstrap
export LAMBDA_RUNTIME_DIR="$(dirname "$0")/../nodejs"
exec "$LAMBDA_RUNTIME_DIR/bootstrap" "$@"

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = require("node:path");
const node_child_process_1 = require("node:child_process");
const nodeBin = (0, node_path_1.join)(__dirname, 'bin', 'node');
const bootstrap = (0, node_path_1.join)(__dirname, '..', 'nodejs', 'bootstrap.js');
(0, node_child_process_1.spawn)(nodeBin, [bootstrap], { stdio: 'inherit' });
//# sourceMappingURL=bootstrap.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../../src/runtimes/nodejs10.x/bootstrap.ts"],"names":[],"mappings":";;AAAA,yCAAiC;AACjC,2DAA2C;AAE3C,MAAM,OAAO,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAC/C,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;AAClE,IAAA,0BAAK,EAAC,OAAO,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC"}

View file

@ -0,0 +1,2 @@
import { Runtime } from '../../types';
export declare function init({ cacheDir }: Runtime): Promise<void>;

View file

@ -0,0 +1,24 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
const install_node_1 = require("../../install-node");
const runtimes_1 = require("../../runtimes");
function init({ cacheDir }) {
return __awaiter(this, void 0, void 0, function* () {
yield Promise.all([
(0, runtimes_1.initializeRuntime)(runtimes_1.runtimes.nodejs),
(0, install_node_1.installNode)(cacheDir, '10.15.3')
]);
});
}
exports.init = init;
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtimes/nodejs10.x/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qDAAiD;AACjD,6CAA6D;AAE7D,SAAsB,IAAI,CAAC,EAAE,QAAQ,EAAW;;QAC/C,MAAM,OAAO,CAAC,GAAG,CAAC;YACjB,IAAA,4BAAiB,EAAC,mBAAQ,CAAC,MAAM,CAAC;YAClC,IAAA,0BAAW,EAAC,QAAQ,EAAE,SAAS,CAAC;SAChC,CAAC,CAAC;IACJ,CAAC;CAAA;AALD,oBAKC"}

View file

@ -0,0 +1,9 @@
#!/bin/sh
set -eu
# Ensure the downloaded Node.js version is used
export PATH="$LAMBDA_RUNTIME_DIR/bin:$PATH"
# Execute the "nodejs" runtime bootstrap
export LAMBDA_RUNTIME_DIR="$(dirname "$0")/../nodejs"
exec "$LAMBDA_RUNTIME_DIR/bootstrap" "$@"

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = require("node:path");
const node_child_process_1 = require("node:child_process");
const nodeBin = (0, node_path_1.join)(__dirname, 'bin', 'node');
const bootstrap = (0, node_path_1.join)(__dirname, '..', 'nodejs', 'bootstrap.js');
(0, node_child_process_1.spawn)(nodeBin, [bootstrap], { stdio: 'inherit' });
//# sourceMappingURL=bootstrap.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../../src/runtimes/nodejs12.x/bootstrap.ts"],"names":[],"mappings":";;AAAA,yCAAiC;AACjC,2DAA2C;AAE3C,MAAM,OAAO,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAC/C,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;AAClE,IAAA,0BAAK,EAAC,OAAO,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC"}

View file

@ -0,0 +1,2 @@
import { Runtime } from '../../types';
export declare function init({ cacheDir }: Runtime): Promise<void>;

View file

@ -0,0 +1,24 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
const install_node_1 = require("../../install-node");
const runtimes_1 = require("../../runtimes");
function init({ cacheDir }) {
return __awaiter(this, void 0, void 0, function* () {
yield Promise.all([
(0, runtimes_1.initializeRuntime)(runtimes_1.runtimes.nodejs),
(0, install_node_1.installNode)(cacheDir, '12.22.7')
]);
});
}
exports.init = init;
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtimes/nodejs12.x/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qDAAiD;AACjD,6CAA6D;AAE7D,SAAsB,IAAI,CAAC,EAAE,QAAQ,EAAW;;QAC/C,MAAM,OAAO,CAAC,GAAG,CAAC;YACjB,IAAA,4BAAiB,EAAC,mBAAQ,CAAC,MAAM,CAAC;YAClC,IAAA,0BAAW,EAAC,QAAQ,EAAE,SAAS,CAAC;SAChC,CAAC,CAAC;IACJ,CAAC;CAAA;AALD,oBAKC"}

View file

@ -0,0 +1,9 @@
#!/bin/sh
set -eu
# Ensure the downloaded Node.js version is used
export PATH="$LAMBDA_RUNTIME_DIR/bin:$PATH"
# Execute the "nodejs" runtime bootstrap
export LAMBDA_RUNTIME_DIR="$(dirname "$0")/../nodejs"
exec "$LAMBDA_RUNTIME_DIR/bootstrap" "$@"

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = require("node:path");
const node_child_process_1 = require("node:child_process");
const nodeBin = (0, node_path_1.join)(__dirname, 'bin', 'node');
const bootstrap = (0, node_path_1.join)(__dirname, '..', 'nodejs', 'bootstrap.js');
(0, node_child_process_1.spawn)(nodeBin, [bootstrap], { stdio: 'inherit' });
//# sourceMappingURL=bootstrap.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../../src/runtimes/nodejs14.x/bootstrap.ts"],"names":[],"mappings":";;AAAA,yCAAiC;AACjC,2DAA2C;AAE3C,MAAM,OAAO,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAC/C,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;AAClE,IAAA,0BAAK,EAAC,OAAO,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC"}

View file

@ -0,0 +1,2 @@
import { Runtime } from '../../types';
export declare function init({ cacheDir }: Runtime): Promise<void>;

View file

@ -0,0 +1,24 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
const install_node_1 = require("../../install-node");
const runtimes_1 = require("../../runtimes");
function init({ cacheDir }) {
return __awaiter(this, void 0, void 0, function* () {
yield Promise.all([
(0, runtimes_1.initializeRuntime)(runtimes_1.runtimes.nodejs),
(0, install_node_1.installNode)(cacheDir, '14.18.1')
]);
});
}
exports.init = init;
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtimes/nodejs14.x/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qDAAiD;AACjD,6CAA6D;AAE7D,SAAsB,IAAI,CAAC,EAAE,QAAQ,EAAW;;QAC/C,MAAM,OAAO,CAAC,GAAG,CAAC;YACjB,IAAA,4BAAiB,EAAC,mBAAQ,CAAC,MAAM,CAAC;YAClC,IAAA,0BAAW,EAAC,QAAQ,EAAE,SAAS,CAAC;SAChC,CAAC,CAAC;IACJ,CAAC;CAAA;AALD,oBAKC"}

View file

@ -0,0 +1,9 @@
#!/bin/sh
set -eu
# Ensure the downloaded Node.js version is used
export PATH="$LAMBDA_RUNTIME_DIR/bin:$PATH"
# Execute the "nodejs" runtime bootstrap
export LAMBDA_RUNTIME_DIR="$(dirname "$0")/../nodejs"
exec "$LAMBDA_RUNTIME_DIR/bootstrap" "$@"

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = require("node:path");
const node_child_process_1 = require("node:child_process");
const nodeBin = (0, node_path_1.join)(__dirname, 'bin', 'node');
const bootstrap = (0, node_path_1.join)(__dirname, '..', 'nodejs', 'bootstrap.js');
(0, node_child_process_1.spawn)(nodeBin, [bootstrap], { stdio: 'inherit' });
//# sourceMappingURL=bootstrap.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../../src/runtimes/nodejs6.10/bootstrap.ts"],"names":[],"mappings":";;AAAA,yCAAiC;AACjC,2DAA2C;AAE3C,MAAM,OAAO,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAC/C,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;AAClE,IAAA,0BAAK,EAAC,OAAO,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC"}

View file

@ -0,0 +1,2 @@
import { Runtime } from '../../types';
export declare function init({ cacheDir }: Runtime): Promise<void>;

View file

@ -0,0 +1,24 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
const install_node_1 = require("../../install-node");
const runtimes_1 = require("../../runtimes");
function init({ cacheDir }) {
return __awaiter(this, void 0, void 0, function* () {
yield Promise.all([
(0, runtimes_1.initializeRuntime)(runtimes_1.runtimes.nodejs),
(0, install_node_1.installNode)(cacheDir, '6.10.0')
]);
});
}
exports.init = init;
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtimes/nodejs6.10/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qDAAiD;AACjD,6CAA6D;AAE7D,SAAsB,IAAI,CAAC,EAAE,QAAQ,EAAW;;QAC/C,MAAM,OAAO,CAAC,GAAG,CAAC;YACjB,IAAA,4BAAiB,EAAC,mBAAQ,CAAC,MAAM,CAAC;YAClC,IAAA,0BAAW,EAAC,QAAQ,EAAE,QAAQ,CAAC;SAC/B,CAAC,CAAC;IACJ,CAAC;CAAA;AALD,oBAKC"}

View file

@ -0,0 +1,9 @@
#!/bin/sh
set -eu
# Ensure the downloaded Node.js version is used
export PATH="$LAMBDA_RUNTIME_DIR/bin:$PATH"
# Execute the "nodejs" runtime bootstrap
export LAMBDA_RUNTIME_DIR="$(dirname "$0")/../nodejs"
exec "$LAMBDA_RUNTIME_DIR/bootstrap" "$@"

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = require("node:path");
const node_child_process_1 = require("node:child_process");
const nodeBin = (0, node_path_1.join)(__dirname, 'bin', 'node');
const bootstrap = (0, node_path_1.join)(__dirname, '..', 'nodejs', 'bootstrap.js');
(0, node_child_process_1.spawn)(nodeBin, [bootstrap], { stdio: 'inherit' });
//# sourceMappingURL=bootstrap.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../../src/runtimes/nodejs8.10/bootstrap.ts"],"names":[],"mappings":";;AAAA,yCAAiC;AACjC,2DAA2C;AAE3C,MAAM,OAAO,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAC/C,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;AAClE,IAAA,0BAAK,EAAC,OAAO,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC"}

View file

@ -0,0 +1,2 @@
import { Runtime } from '../../types';
export declare function init({ cacheDir }: Runtime): Promise<void>;

View file

@ -0,0 +1,24 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
const install_node_1 = require("../../install-node");
const runtimes_1 = require("../../runtimes");
function init({ cacheDir }) {
return __awaiter(this, void 0, void 0, function* () {
yield Promise.all([
(0, runtimes_1.initializeRuntime)(runtimes_1.runtimes.nodejs),
(0, install_node_1.installNode)(cacheDir, '8.10.0')
]);
});
}
exports.init = init;
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtimes/nodejs8.10/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qDAAiD;AACjD,6CAA6D;AAE7D,SAAsB,IAAI,CAAC,EAAE,QAAQ,EAAW;;QAC/C,MAAM,OAAO,CAAC,GAAG,CAAC;YACjB,IAAA,4BAAiB,EAAC,mBAAQ,CAAC,MAAM,CAAC;YAClC,IAAA,0BAAW,EAAC,QAAQ,EAAE,QAAQ,CAAC;SAC/B,CAAC,CAAC;IACJ,CAAC;CAAA;AALD,oBAKC"}

View file

@ -0,0 +1,3 @@
#!/bin/bash
# Delegate out to the provided `bootstrap` file
exec "$LAMBDA_TASK_ROOT/bootstrap" "$@"

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = require("node:path");
const node_child_process_1 = require("node:child_process");
// Delegate out to the provided `bootstrap` file within the lambda
const bootstrap = (0, node_path_1.join)(process.env.LAMBDA_TASK_ROOT, 'bootstrap');
(0, node_child_process_1.spawn)(bootstrap, [], { stdio: 'inherit' });
//# sourceMappingURL=bootstrap.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../../src/runtimes/provided/bootstrap.ts"],"names":[],"mappings":";;AAAA,yCAAiC;AACjC,2DAA2C;AAE3C,kEAAkE;AAClE,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAC;AAClE,IAAA,0BAAK,EAAC,SAAS,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC"}

10
node_modules/@vercel/fun/dist/src/runtimes/python/bootstrap generated vendored Executable file
View file

@ -0,0 +1,10 @@
#!/bin/sh
set -eu
# `PYTHONPATH` is *not* a restricted env var, so only set the
# default one if the user did not provide one of their own
if [ -z "${PYTHONPATH-}" ]; then
export PYTHONPATH="$LAMBDA_RUNTIME_DIR"
fi
exec python "$LAMBDA_RUNTIME_DIR/bootstrap.py"

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = require("node:path");
const node_child_process_1 = require("node:child_process");
// `PYTHONPATH` is *not* a restricted env var, so only set the
// default one if the user did not provide one of their own
if (!process.env.PYTHONPATH) {
process.env.PYTHONPATH = process.env.LAMBDA_RUNTIME_DIR;
}
const bootstrap = (0, node_path_1.join)(__dirname, 'bootstrap.py');
(0, node_child_process_1.spawn)('python', [bootstrap], { stdio: 'inherit' });
//# sourceMappingURL=bootstrap.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../../src/runtimes/python/bootstrap.ts"],"names":[],"mappings":";;AAAA,yCAAiC;AACjC,2DAA2C;AAE3C,8DAA8D;AAC9D,2DAA2D;AAC3D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;CACxD;AAED,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,cAAc,CAAC,CAAC;AAClD,IAAA,0BAAK,EAAC,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC"}

View file

@ -0,0 +1,147 @@
# Parts of this runtime based off of:
# https://gist.github.com/avoidik/78ddc7854c7b88607f7cf56db3e591e5
import os
import sys
import json
import importlib
is_python_3 = sys.version_info > (3, 0)
if is_python_3:
import urllib.request
else:
import urllib2
class LambdaRequest:
def __init__(self, path, data=None):
req = None
runtime_path = '/2018-06-01/runtime/'
url = (
'http://'
+ os.environ.get(
'AWS_LAMBDA_RUNTIME_API', '127.0.0.1:3000'
)
+ runtime_path
+ path
)
if is_python_3:
req = urllib.request.urlopen(url, data)
else:
req = urllib2.urlopen(url, data)
info = req.info()
body = req.read()
if is_python_3:
body = body.decode(encoding='UTF-8')
self.status_code = req.getcode()
self.body = body
self.info = info
def get_header(self, name):
if is_python_3:
return self.info.get(name)
else:
return self.info.getheader(name)
def get_json_body(self):
return json.loads(self.body)
def lambda_runtime_next_invocation():
res = LambdaRequest('invocation/next')
if res.status_code != 200:
raise Exception(
'Unexpected /invocation/next response: '
+ res.body
)
x_amzn_trace_id = res.get_header('Lambda-Runtime-Trace-Id')
if x_amzn_trace_id != None:
os.environ['_X_AMZN_TRACE_ID'] = x_amzn_trace_id
elif '_X_AMZN_TRACE_ID' in os.environ:
del os.environ['_X_AMZN_TRACE_ID']
aws_request_id = res.get_header('Lambda-Runtime-Aws-Request-Id')
context = {
# TODO: fill this out
'aws_request_id': aws_request_id
}
event = res.get_json_body()
return (event, context)
def lambda_runtime_invoke_response(result, context):
body = json.dumps(result, separators=(',', ':')).encode(
encoding='UTF-8'
)
res = LambdaRequest(
'invocation/'
+ context['aws_request_id']
+ '/response',
body,
)
if res.status_code != 202:
raise Exception(
'Unexpected /invocation/response response: '
+ res.body
)
def lambda_runtime_invoke_error(err, context):
body = json.dumps(err, separators=(',', ':')).encode(
encoding='UTF-8'
)
res = LambdaRequest(
'invocation/'
+ context['aws_request_id']
+ '/error',
body,
)
def lambda_runtime_get_handler():
(module_name, handler_name) = os.environ['_HANDLER'].split('.')
mod = importlib.import_module(module_name)
# TODO: invoke `__init__`?
return getattr(mod, handler_name)
def lambda_runtime_main():
if not is_python_3:
reload(sys)
sys.setdefaultencoding('utf-8')
sys.path.insert(
0, os.environ.get('LAMBDA_TASK_ROOT', '/var/task')
)
fn = lambda_runtime_get_handler()
while True:
(event, context) = lambda_runtime_next_invocation()
# print(event)
# print(context)
result = None
try:
result = fn(event, context)
except:
err = str(sys.exc_info()[0])
print(err)
lambda_runtime_invoke_error(
{'error': err}, context
)
else:
lambda_runtime_invoke_response(result, context)
if __name__ == '__main__':
lambda_runtime_main()

View file

@ -0,0 +1,9 @@
#!/bin/sh
set -eu
# Ensure the downloaded Python version is used
export PATH="$LAMBDA_RUNTIME_DIR/bin:$PATH"
# Execute the "python" runtime bootstrap
export LAMBDA_RUNTIME_DIR="$(dirname "$0")/../python"
exec "$LAMBDA_RUNTIME_DIR/bootstrap" "$@"

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = require("node:path");
const node_child_process_1 = require("node:child_process");
const pythonBin = (0, node_path_1.join)(__dirname, 'bin', 'python');
const bootstrap = (0, node_path_1.join)(__dirname, '..', 'python', 'bootstrap.py');
(0, node_child_process_1.spawn)(pythonBin, [bootstrap], { stdio: 'inherit' });
//# sourceMappingURL=bootstrap.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../../src/runtimes/python2.7/bootstrap.ts"],"names":[],"mappings":";;AAAA,yCAAiC;AACjC,2DAA2C;AAE3C,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AACnD,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;AAClE,IAAA,0BAAK,EAAC,SAAS,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC"}

View file

@ -0,0 +1,2 @@
import { Runtime } from '../../types';
export declare function init({ cacheDir }: Runtime): Promise<void>;

View file

@ -0,0 +1,24 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
const install_python_1 = require("../../install-python");
const runtimes_1 = require("../../runtimes");
function init({ cacheDir }) {
return __awaiter(this, void 0, void 0, function* () {
yield Promise.all([
(0, runtimes_1.initializeRuntime)(runtimes_1.runtimes.python),
(0, install_python_1.installPython)(cacheDir, '2.7.12')
]);
});
}
exports.init = init;
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtimes/python2.7/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,yDAAqD;AACrD,6CAA6D;AAE7D,SAAsB,IAAI,CAAC,EAAE,QAAQ,EAAW;;QAC/C,MAAM,OAAO,CAAC,GAAG,CAAC;YACjB,IAAA,4BAAiB,EAAC,mBAAQ,CAAC,MAAM,CAAC;YAClC,IAAA,8BAAa,EAAC,QAAQ,EAAE,QAAQ,CAAC;SACjC,CAAC,CAAC;IACJ,CAAC;CAAA;AALD,oBAKC"}

View file

@ -0,0 +1,9 @@
#!/bin/sh
set -eu
# Ensure the downloaded Python version is used
export PATH="$LAMBDA_RUNTIME_DIR/bin:$PATH"
# Execute the "python" runtime bootstrap
export LAMBDA_RUNTIME_DIR="$(dirname "$0")/../python"
exec "$LAMBDA_RUNTIME_DIR/bootstrap" "$@"

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = require("node:path");
const node_child_process_1 = require("node:child_process");
const pythonBin = (0, node_path_1.join)(__dirname, 'bin', 'python');
const bootstrap = (0, node_path_1.join)(__dirname, '..', 'python', 'bootstrap.py');
(0, node_child_process_1.spawn)(pythonBin, [bootstrap], { stdio: 'inherit' });
//# sourceMappingURL=bootstrap.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../../src/runtimes/python3.6/bootstrap.ts"],"names":[],"mappings":";;AAAA,yCAAiC;AACjC,2DAA2C;AAE3C,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AACnD,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;AAClE,IAAA,0BAAK,EAAC,SAAS,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC"}

View file

@ -0,0 +1,2 @@
import { Runtime } from '../../types';
export declare function init({ cacheDir }: Runtime): Promise<void>;

View file

@ -0,0 +1,24 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
const install_python_1 = require("../../install-python");
const runtimes_1 = require("../../runtimes");
function init({ cacheDir }) {
return __awaiter(this, void 0, void 0, function* () {
yield Promise.all([
(0, runtimes_1.initializeRuntime)(runtimes_1.runtimes.python),
(0, install_python_1.installPython)(cacheDir, '3.6.8')
]);
});
}
exports.init = init;
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtimes/python3.6/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,yDAAqD;AACrD,6CAA6D;AAE7D,SAAsB,IAAI,CAAC,EAAE,QAAQ,EAAW;;QAC/C,MAAM,OAAO,CAAC,GAAG,CAAC;YACjB,IAAA,4BAAiB,EAAC,mBAAQ,CAAC,MAAM,CAAC;YAClC,IAAA,8BAAa,EAAC,QAAQ,EAAE,OAAO,CAAC;SAChC,CAAC,CAAC;IACJ,CAAC;CAAA;AALD,oBAKC"}

View file

@ -0,0 +1,9 @@
#!/bin/sh
set -eu
# Ensure the downloaded Python version is used
export PATH="$LAMBDA_RUNTIME_DIR/bin:$PATH"
# Execute the "python" runtime bootstrap
export LAMBDA_RUNTIME_DIR="$(dirname "$0")/../python"
exec "$LAMBDA_RUNTIME_DIR/bootstrap" "$@"

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = require("node:path");
const node_child_process_1 = require("node:child_process");
const pythonBin = (0, node_path_1.join)(__dirname, 'bin', 'python');
const bootstrap = (0, node_path_1.join)(__dirname, '..', 'python', 'bootstrap.py');
(0, node_child_process_1.spawn)(pythonBin, [bootstrap], { stdio: 'inherit' });
//# sourceMappingURL=bootstrap.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../../src/runtimes/python3.7/bootstrap.ts"],"names":[],"mappings":";;AAAA,yCAAiC;AACjC,2DAA2C;AAE3C,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AACnD,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;AAClE,IAAA,0BAAK,EAAC,SAAS,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC"}

View file

@ -0,0 +1,2 @@
import { Runtime } from '../../types';
export declare function init({ cacheDir }: Runtime): Promise<void>;

View file

@ -0,0 +1,24 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
const install_python_1 = require("../../install-python");
const runtimes_1 = require("../../runtimes");
function init({ cacheDir }) {
return __awaiter(this, void 0, void 0, function* () {
yield Promise.all([
(0, runtimes_1.initializeRuntime)(runtimes_1.runtimes.python),
(0, install_python_1.installPython)(cacheDir, '3.7.2')
]);
});
}
exports.init = init;
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtimes/python3.7/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,yDAAqD;AACrD,6CAA6D;AAE7D,SAAsB,IAAI,CAAC,EAAE,QAAQ,EAAW;;QAC/C,MAAM,OAAO,CAAC,GAAG,CAAC;YACjB,IAAA,4BAAiB,EAAC,mBAAQ,CAAC,MAAM,CAAC;YAClC,IAAA,8BAAa,EAAC,QAAQ,EAAE,OAAO,CAAC;SAChC,CAAC,CAAC;IACJ,CAAC;CAAA;AALD,oBAKC"}

20
node_modules/@vercel/fun/dist/src/runtimes/python3/bootstrap generated vendored Executable file
View file

@ -0,0 +1,20 @@
#!/bin/sh
set -eu
# Use the system installed python3
PYTHONBIN="$( command -v python3 || command -v python || echo '' )"
if [ -z "$PYTHONBIN" ]; then
echo "Please install Python 3"
exit 1
fi
# Check if python version is 3
PYTHONVERSION="$( "$PYTHONBIN" --version 2>&1 )"
case "$PYTHONVERSION" in
"Python 3"*) ;;
*) echo "Please install Python 3" && exit 1 ;;
esac
# Execute the "python" runtime bootstrap
export LAMBDA_RUNTIME_DIR="$(dirname "$0")/../python"
exec "$PYTHONBIN" "$LAMBDA_RUNTIME_DIR/bootstrap.py" "$@"

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = require("node:path");
const node_child_process_1 = require("node:child_process");
// `PYTHONPATH` is *not* a restricted env var, so only set the
// default one if the user did not provide one of their own
if (!process.env.PYTHONPATH) {
process.env.PYTHONPATH = process.env.LAMBDA_RUNTIME_DIR;
}
let pythonBin = 'python3';
function fallback() {
pythonBin = 'python';
}
function handler(data) {
const isPython3 = data && data.startsWith('Python 3');
if (!isPython3) {
fallback();
}
const bootstrap = (0, node_path_1.join)(__dirname, '..', 'python', 'bootstrap.py');
(0, node_child_process_1.spawn)(pythonBin, [bootstrap], { stdio: 'inherit' });
}
const child = (0, node_child_process_1.spawn)(pythonBin, ['--version']);
child.on('error', fallback);
Promise.all([child.stdout, child.stderr].map(stream2Promise)).then(([stdout, stderr]) => {
// if there are stderr messages, then we know the python version is not 3
if (stderr.length) {
handler();
}
else {
handler(stdout.toString());
}
});
function stream2Promise(stream) {
const buffers = [];
return new Promise(resolve => {
stream.on('data', data => buffers.push(data));
stream.on('end', () => resolve(Buffer.concat(buffers)));
});
}
//# sourceMappingURL=bootstrap.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../../src/runtimes/python3/bootstrap.ts"],"names":[],"mappings":";;AAAA,yCAAiC;AACjC,2DAA2C;AAE3C,8DAA8D;AAC9D,2DAA2D;AAC3D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;CACxD;AAED,IAAI,SAAS,GAAG,SAAS,CAAC;AAC1B,SAAS,QAAQ;IAChB,SAAS,GAAG,QAAQ,CAAC;AACtB,CAAC;AACD,SAAS,OAAO,CAAC,IAAa;IAC7B,MAAM,SAAS,GAAG,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAEtD,IAAI,CAAC,SAAS,EAAE;QACf,QAAQ,EAAE,CAAC;KACX;IAED,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;IAClE,IAAA,0BAAK,EAAC,SAAS,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AACrD,CAAC;AACD,MAAM,KAAK,GAAG,IAAA,0BAAK,EAAC,SAAS,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;AAC9C,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAE5B,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CACjE,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE;IACpB,yEAAyE;IACzE,IAAI,MAAM,CAAC,MAAM,EAAE;QAClB,OAAO,EAAE,CAAC;KACV;SAAM;QACN,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;KAC3B;AACF,CAAC,CACD,CAAC;AAEF,SAAS,cAAc,CAAC,MAA6B;IACpD,MAAM,OAAO,GAAG,EAAE,CAAC;IACnB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QAC5B,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC9C,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACJ,CAAC"}

View file

@ -0,0 +1,2 @@
import { Runtime } from '../../types';
export declare function init(_runtime: Runtime): Promise<void>;

View file

@ -0,0 +1,20 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
const runtimes_1 = require("../../runtimes");
function init(_runtime) {
return __awaiter(this, void 0, void 0, function* () {
yield (0, runtimes_1.initializeRuntime)(runtimes_1.runtimes.python);
});
}
exports.init = init;
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtimes/python3/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,6CAA6D;AAE7D,SAAsB,IAAI,CAAC,QAAiB;;QAC3C,MAAM,IAAA,4BAAiB,EAAC,mBAAQ,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC;CAAA;AAFD,oBAEC"}