Git Product home page Git Product logo

deno-lambda's Introduction

deno on AWS Lambda

A deno runtime for AWS Lambda.

Deploy deno code via docker container or bundle it yourself.

ci status

Define a handler function, for example:

// hello.ts

import {
  APIGatewayProxyEventV2,
  APIGatewayProxyResultV2,
  Context,
} from "https://deno.land/x/lambda/mod.ts";

export async function handler(
  event: APIGatewayProxyEventV2,
  context: Context,
): Promise<APIGatewayProxyResultV2> {
  return {
    body: `Welcome to deno ${Deno.version.deno} 🦕`,
    headers: { "content-type": "text/html;charset=utf8" },
    statusCode: 200,
  };
}

Here the handler is hello.handler but this can be configured by the Handler setting.

Configuration

The following environment variables can be set to change deno-lambda's behavior:

  • HANDLER_EXT to set supported extension of handler file e.g. js or bundle.js (default ts).
  • DENO_CONFIG so deno runs with --config=$DENO_CONFIG.
  • DENO_DIR so deno runs with DENO_DIR=$DENO_DIR deno ....
  • DENO_IMPORTMAP so deno runs with --importmap=$DENO_IMPORTMAP.
  • DENO_LOCATION so deno runs with --location=$DENO_LOCATION.
  • DENO_LOCK so deno runs with --lock=$DENO_LOCK.
  • DENO_PERMISSIONS so deno only runs with a specific list of permissions. Deno lambda requires at least --allow-env and --allow-net.
  • DENO_PREFIX prepends to console.log etc. a template literal, this can include requestId and level variables only (default ${level}\tRequestId: ${requestId}\r).
  • DENO_UNSTABLE so deno runs with the --unstable.

Further configuration TBD.

Types

deno-lambda exports Definitely Typed's aws-lambda types, listed in https://deno.land/x/lambda/mod.ts and defined in https://deno.land/x/lambda/types.d.ts.

It's good practice to reference the trigger's type in the handler, for example: APIGateway use APIGatewayProxyEventV2 and APIGatewayProxyResultV2, SQS use SQSEvent, etc.

Note: Despite there being multiple interfaces with the Context suffix, the second handler argument must be Context. These other interfaces can be accessed from the first argument (the event), for example event.requestContext of an APIGatewayProxyEventV2.

How to deploy

See the deno_dir-remapping section for how to include the correct DENO_DIR files to avoid any runtime compilation.

Warning

The way the lambda platform works means that promises not awaited in the handler may never be completed. This is because the underlying container can be suspended between invocations and will sometimes be shutdown afterwards.

export async function badHandler(
  event: APIGatewayProxyEventV2,
  context: Context,
): Promise<APIGatewayProxyResultV2> {
  somethingAsync(); // not awaited so may not complete
  return { statusCode: 200, body: "" };
}

export async function goodHandler(
  event: APIGatewayProxyEventV2,
  context: Context,
): Promise<APIGatewayProxyResultV2> {
  await somethingAsync();
  return { statusCode: 200, body: "" };
}

If you need to return immediately but want to invoke a longer running process you can async-invoke another lambda function (that does the await somethingAsync()).

Related projects


Bundling code

Create a zip file which contains:

  • an entry point which exports an async function (e.g. hello.ts)
  • include any other files needed to run the entry file
  • (optional but preferred) .deno_dir directory

*You can use a different directory with DENO_DIR environment variable.

Alternatively use deno bundle command and include the outputted js file, see also HANDLER_EXT.

DENO_DIR remapping

In order for compile artifacts to be recovered (and avoid runtime compilation) you must do the following directory remapping:

# Compile the handler (and cache dependencies and compile artifacts into DENO_DIR).
DENO_DIR=.deno_dir deno cache hello.ts

# This is the "remapping" step:
cp -R .deno_dir/gen/file/$PWD/ .deno_dir/LAMBDA_TASK_ROOT
# Note: We do the inverse of this operation in bootstrap.

zip lambda.zip -x '.deno_dir/gen/file/*' -r .deno_dir hello.ts  # other source files

Testing locally with docker-lambda

You can execute deno-lambda locally using docker-lambda. First, unzip the deno-lambda-layer.zip layer into a directory.

Now, from the directory of your application:

# replace LAYER_DIR with the directory you unzipped the layer to e.g. $PWD/layer
# replace hello.handler with your file/handler function
# replace '{}' with the json to pass to the handler
$ docker run -it --rm -v "$PWD":/var/task:ro,delegated -v "LAYER_DIR":/opt:ro,delegated lambci/lambda:provided.al2 hello.handler '{}'
# handler response from goes to stdout

To execute multiple times AKA "stay-open" API mode:

# replace LAYER_DIR with the directory you unzipped to e.g. $PWD/layer
# replace hello.handler with your file.handler function
$ docker run -e DOCKER_LAMBDA_STAY_OPEN=1 -p 9001:9001 -it --rm -v "$PWD":/var/task:ro,delegated -v "LAYER_DIR":/opt:ro,delegated lambci/lambda:provided.al2 hello.handler
Lambda API listening on port 9001...

and in another terminal:

# replace '{}' with the json to pass to the handler
$ aws lambda invoke --endpoint http://localhost:9001 --no-sign-request --function-name deno-func --payload '{}' output.json
# output.json is populated with the handler response

For more advanced usage, e.g. including multiple layers and installing additional libraries (with yumbda), please consult the docker-lambda documentation.

Advanced logging

You can set the way console.log etc. outputs to cloudwatch logs using DENO_PREFIX. You can include the line number using ${(new Error).stack.split('\n')[4]} or the datetime using ${new Date().toISOString()} (though the datetime of every cloudwatch event is part of the event itself.

Use these as a template literal, for example:

DENO_PREFIX=${level}\t${requestId}\t${(new Error).stack.split('\n')[4]}\r

This will prefix each log with the level, the request id and the line number:

Screen Shot 2020-02-11 at 18 12 42


Thanks

Thanks to Andy Hayden for setting up the original https://github.com/hayd/deno-lambda repo.

Many thanks to Yoshiya Hinosawa's blogpost for the initial work on this runtime.

deno-lambda's People

Contributors

alon2303 avatar bartlomieju avatar brianleroux avatar ceifa avatar denobot avatar dependabot[bot] avatar hayd avatar igorzi avatar ije avatar kim-cloudconformity avatar lsagetlethias avatar lucacasonato avatar turlockmike avatar web-flow avatar wperron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deno-lambda's Issues

can not find deno with https://github.com/lambci/docker-lambda?

hi,
I tried to play this with local lambda, while getting the below error:

111 #### PATH=/var/task/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin
222 #### pwd=/var/task
/var/task/bootstrap: line 238: deno: command not found

line 238 is below line, i tried to echo out the path and pwd
https://github.com/hayd/deno-lambda/blob/master/runtime/bootstrap#L236

reckon if it's related to lambda image ? because that deno can not run in Mac as well

BTW, what is https://github.com/hayd/deno-lambda/releases/download/1.0.2/amz-deno.gz and what it's for?

Understanding Remapping

I'm just trying to understand why we need to remap the DENO_DIR? I have read through DENO_DIR Remapping but don't understand why $ deno bundle would not work? Does $ deno bundle not include external modules?

Thanks in advance for clarifying.

Release Amazon Linux1 / CentOS7 builds

@hayd, referencing this comment, could you please re-enable builds for CentOS7 (i.e., Amazon Linux 1) builds?

It doesn't look like Deno will supply official binaries for CentOS7.

Thanks in advance!

Use the new Lambda Container runtime

AWS recently announced support for Docker runtimes for Lambda. They have provided base images, one of which is the "provided" image for custom runtimes.

Fundamentally the runtime still works the same, it just supports a new upload format on top of the current zip one. All that would need to be done is adding a Dockerfile to the repo. The current runtime and layer could still be published and used the same as they currently are, but the Dockerfile could potentially make it easier to test, and by publishing an image to a public ECR repo it would give yet another option for deploying Deno applications to Lambda.

console.log format ?

In node console.log(XXX) is prefixed with:

2020-01-17T04:36:04.408Z 330af918-dcb6-448d-945a-60e6c9c0a63d INFO XXX

should this be the case in deno-lambda?

Note:

  • The id is the request id (which is useful to have as you can look up all the log events from a given request)... which were printed via console (not direct to stdout).
  • The time stamp is superfluous since it's included in the event metadata.
  • It's INFO when it's console.log which seems strange. Why is that?
  • Other platforms (python) don't do this.

My opinion is the timestamp is unnecessary and noisy:

`${REQUEST_ID}\tINFO\tXXX`

is better...

Puppeteer

I've been trying to get puppeteer running in this Dockerfile.

FROM hayd/deno-lambda:1.13.2
ENV PUPPETEER_PRODUCT=chrome
RUN deno run -A --unstable https://deno.land/x/[email protected]/install.ts
COPY hello.ts .
RUN deno cache --unstable hello.ts
CMD ["hello.handler"]

and hello.ts:

import {
  APIGatewayProxyEventV2,
  APIGatewayProxyResultV2,
  Context,
} from "https://deno.land/x/lambda/mod.ts";
import puppeteer from "https://deno.land/x/[email protected]/mod.ts";

export async function handler(
  event: APIGatewayProxyEventV2,
  context: Context,
): Promise<APIGatewayProxyResultV2> {
  console.log('start');
  const browser = await puppeteer.launch({
    headless: true,
    args: [
      "--no-sandbox",
      "--disable-dev-shm-usage",
    ]
  });
  const page = (await browser.pages())[0];
  await browser.close();
  console.log('finish');
  return {
    statusCode: 200,
    headers: { "content-type": "text/html;charset=utf8" },
    body: `Welcome to deno ${Deno.version.deno} 🦕`,
  };
}

Gets:
Error: Could not find browser revision 869685. Run "PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/[email protected]/install.ts" to download a supported browser binary.

It seems that the RUN deno run -A --unstable https://deno.land/x/[email protected]/install.ts doesn't persist chrome into the image, as RUN chrome after it doesn't work.

I've also tried to install chrome by RUN curl https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm -o ./google-chrome-stable_current_x86_64.rpm && yum install ./google-chrome-stable_current_x86_64.rpm -y && ln -s /usr/bin/google-chrome-stable /usr/bin/chrome where RUN chrome now works but still get the same error.

Example sam template is not supported by SAM

Thanks for the work on this project, I burned a lot of time trying to compile deno for an AWS environment. I'm hoping projects like this will gain traction for deno.

I have used the template examples to build a serverless application using SAM. I then use it to deploy the custom layers. I am now trying to deploy a serverless function that uses the custom runtime however the "provided" is throwing the following error:

$ sam build --template packaged.yaml --region us-east-1
Build Failed
Error: 'provided' runtime is not supported

Here is an issue tracking this

edit: layers

Test console logging

Currently stdout and stderr cannot be read since the bootstrap script is killed.

This will be easier if the http server were closed properly (rather than killed).
Edit: This should be feasible now we're using 0.24.0.

Deno issue: denoland/deno#3416.

Note: stdout DOES get posted to CW logs as it stands, this simply isn't tested in CI. For more advanced console.log handling see #40.

Invoke lambda locally with serverless invoke

I am not able to invoke lambda locally with Serverless framework with sls invoke local -f ...
All works well when I deploy my lambda, but when I try to run it locally I have the following error:
Failed to run docker for provided.al2 image. Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap]
If it is possible, could you provide some instructions how to do it.
Thanks

How get fields from event(APIGatewayProxyEvent)

Hi,
Confused about how to get data from event,
I invoked the function as below:

aws lambda invoke --endpoint http://localhost:8002 --no-sign-request --cli-binary-format raw-in-base64-out \
  --function-name handler --payload '{"field1":11, "tableName":"t1"}' output.json

i can log that event as: { field1: 11, tableName: "t1" }, which is what expected

but having question about how to get it out
As mentioned, event is APIGatewayProxyEvent type, while the data passed-in from above invoke seems not set in APIGatewayProxyEvent type, it means all values of fields from APIGatewayProxyEvent type are empty

Provide bundling instructions

First of all thank you so much for this toolkit, having a deno lambda layer is awesome! 🎉

This is a feature request for users that want to build their own layer. Our company has strict policies against using external layers, so we need to bake and create out own. The instructions in the README assume we are working from the released ZIP. It would be awesome if this was extended to show how to create the layer zip from source.

This would also enable users finer control over the produced layer, in case they wanted to make small source changes before producing the layer zip.

types.ts.d contains references to non-existing sources

I'm unable to import the lambda module when using deno run or deno cache due to export declarations to unavailable sources. See https://github.com/hayd/deno-lambda/blob/853879fa2f45a4b4b75240ba12b9870bf2a3f413/runtime/types.d.ts#L1434-L1444

This seems to have been introduce in https://github.com/DefinitelyTyped/DefinitelyTyped/blob/f7ec78508c6797e42f87a4390735bc2c650a1bfd/types/aws-lambda/trigger/cognito-user-pool-trigger/index.d.ts#L109-L119

Looks like v1.9-1 is fine, and was problematic in v1.10.2

Here's the log

Download https://deno.land/x/lambda/mod.ts
Warning Implicitly using latest version (1.10.2) for https://deno.land/x/lambda/mod.ts
Download https://deno.land/x/[email protected]/mod.ts
Download https://deno.land/x/[email protected]/types.d.ts
Download https://deno.land/x/[email protected]/create-auth-challenge
Download https://deno.land/x/[email protected]/custom-message
Download https://deno.land/x/[email protected]/post-authentication
Download https://deno.land/x/[email protected]/verify-auth-challenge-response
Download https://deno.land/x/[email protected]/custom-email-sender
Download https://deno.land/x/[email protected]/pre-token-generation
Download https://deno.land/x/[email protected]/post-confirmation
Download https://deno.land/x/[email protected]/user-migration
Download https://deno.land/x/[email protected]/define-auth-challenge
Download https://deno.land/x/[email protected]/pre-authentication
Download https://deno.land/x/[email protected]/pre-signup
error: Import 'https://deno.land/x/[email protected]/create-auth-challenge' failed: 404 Not Found
    at https://deno.land/x/[email protected]/types.d.ts:1434:0

Deploy error: "failed to deno bundle"

When I run the hello-world sample laid out in the README I'm getting bundle error on aws/now.
Details in the now logs here: https://zeit.co/phil/deno-tmp/f65urnf02

image

I wonder, has something changed upstream in AWS? Can you guys deploy using this builder to now currently, or may I'm doing something stupid.

Thanks - and THANKS for putting this builder together for deno! This is super helpful to see. 🍰

DENO_DIR cache *maybe* no longer works

Previously

import type {
  Context,
  APIGatewayProxyEvent
} from "https://deno.land/x/lambda/mod.ts";

etc.

the deps and gen were correctly cached (from the layer and the function code), this seems to no longer be the case.

It's unclear to me if it's a zipping issue or due the filenames being renamed (now there's hashes in the name).


I'm not 100% sure this is an issue, but have a suspicion... needs investigate (and ideally a test).

Use same version numbering as deno AKA deno-lambda 1.0

Requires:

  • better typing #18
  • publish to SAR
  • support lockfiles #24
  • support importmap, config, other flags??
  • decide if should have all permissions? i.e. -A
  • missing identity and clientContext on Context #25
  • include SAM example https://github.com/brianleroux/sam-example-deno
  • update serverless example to use SAR
  • reference ARC/other projects (happy to add others if commented here)
  • cleanup README (move the many images to sep documentation?).

anything else?


  • Change QUICK-START to use the SAR app (deploy then look up ARN from Output)
  • Add example of line number and date from DENO_PREFIX in README.
  • Add LicenseInfo=MIT to SAR app's layer (also description etc?)
  • Propagate the tracing header
  • add hello-world SAR application (is there such a thing as user-published "blueprint"?)
  • console.log multiple lines to CW (#40, this is non-trivial due to rate-limiting)
  • settle on console.log format #44
  • use bin/deno rather than amz-deno (amend PATH=/usr/local/bin:/usr/bin/:/bin:/opt/bin and LD_LIBRARY_PATH=/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib in tests to match lambda), this will mean deno is in PATH. #45
  • become "verified" on SAR

import_map causes module not found

I have an otherwise working application that fails if I try to use an import map; specifically the kind of import maps generated by trex. I have created a minimal repro of the issue with this repository. Here is the working version without the import map.

The failure it produces is

2022-05-30T13:22:56.089-07:00 | error: Module not found "file:///var/task/tmp/runtime.js".
-- | --
  | 2022-05-30T13:22:56.133-07:00 | error: deno exited
  | 2022-05-30T13:22:56.219-07:00 | START RequestId: ee82b3a3-6dc4-4f7b-ae89-d7646649862d Version: $LATEST
  | 2022-05-30T13:22:56.822-07:00 | error: Module not found "file:///var/task/tmp/runtime.js".
  | 2022-05-30T13:22:57.303-07:00 | error: deno exited
  | 2022-05-30T13:22:57.443-07:00 | END RequestId: ee82b3a3-6dc4-4f7b-ae89-d7646649862d
  | 2022-05-30T13:22:57.443-07:00 | REPORT RequestId: ee82b3a3-6dc4-4f7b-ae89-d7646649862d Duration: 1222.96 ms Billed Duration: 1223 ms Memory Size: 128 MB Max Memory Used: 12 MB
  | 2022-05-30T13:22:57.443-07:00 | Unknown application error occurred Unhandled
  | 2022-05-30T13:22:57.904-07:00 | error: Module not found "file:///var/task/tmp/runtime.js".
  | 2022-05-30T13:22:57.945-07:00 | error: deno exited

Working Directory is ignored in the Docker Image

I have the following configuration in Terraform:

resource "aws_lambda_function" "this" {
  # ...
  image_config {
    working_directory = "/var/task/foo/bar"
    command           = ["baz.handler"]
  }
}

but the bootstrap script seems to be ignoring the working_directory parameter and tries to import /var/task/baz.js instead of /var/task/foo/bar/baz.js - as a workaround I commented out the parameter and changed the command to ["foo/bar/baz.handler"]

Incorrect version in 0.34.0 SAR release

I'm unable to fix, though I could release as 0.34.1...

Edit: I should get my eyes tested, but the joke is I had just had my eyes tested and my pupils were still dilated 😆 (whoops), apologies for not checking the diff carefully enough.

Benchmarks

Howdy 👋 Just wondering if you had benchmarks for Deno performance on Lambda squirreled away you could share. Trying to convince a team to give this a shot and benchmarks was the first thing they asked for.

DENO_DIR remapping in deno (supporting windows)

At the moment you need to do:

# Compile the handler (and fetch dependencies into DENO_DIR).
DENO_DIR=.deno_dir deno fetch hello.ts

# This is the "remapping" step:
cp -R .deno_dir/gen/file/$PWD/ .deno_dir/LAMBDA_TASK_ROOT
# Note: We do the inverse of this operation in bootstrap.

zip lambda.zip -x '.deno_dir/gen/file/*' -r .deno_dir hello.ts  # other source files

I don't think this works in windows (if it does then this can be done with Deno.run).

Either

  1. rewrite for Windows Deno.run (using the equivalent windows commands, specifically zip)
  2. port/use a deno native zip library (e.g. JSZip, but this doesn't quite work yet).

Add this as https://deno.land/x/lambda/zip.ts (or something). Potentially support .npmignore (since this is respected by SAM it makes sense to emulate that).

`event.path` is returning `undefined`

Using the example from the read me. The request spits out okay. I am really just trying to use severless_oak. I am going through trying to debug it. On Line 22, it uses event.path.

So I decided to take the example from your readme and try to access the path like so:

import {
  APIGatewayProxyEvent,
  APIGatewayProxyResult,
  Context,
} from "https://deno.land/x/lambda/mod.ts";

export async function handler(
  event: APIGatewayProxyEvent,
  context: Context,
): Promise<APIGatewayProxyResult> {
  console.log(event);
  console.log(event.path);
  console.log(context);
  return await {
    body: `Welcome to deno ${Deno.version.deno} 🦕`,
    headers: { "content-type": "text/html;charset=utf8" },
    statusCode: 200,
  };
}

As I said before, the request comes out fine, event looks like it has a path sitting in the http object but typescript prevents me from accessing it and event.path is logging undefined in this example. Any ideas on how to remedy this? This is running aws lambda with amazon linux 2. I followed the SAR guide to deploy. I added an api gateway so i can hit it in my browser instead of using the test function.

Update:
I think I got it. APIGatewayProxyEventV2 is the event type I should be using. I can use rawPath for fetching the path. Then i just configure to API Gateway with a / path so I can hit the server with "XXXX.execute-api.us-east-2.amazonaws.com" and event.rawPath will return /.

Is this the proper way to do this or should I handle this another way? First time deploying a lambda function manually. Usually use serverless with nextjs.

build: run deno fmt in CI

Run deno fmt --check in CI to check that all files have proper formatting. Currently not all files are formatted the same.

console.log multiple lines to a single Cloudwatch Logs event

At the moment each line is a separate event for each line (this is handled by the callee of the custom runtime who is piping stdout to cloudwatch logs).

The objective is to be able to push a single event e.g. console.log(1, '\n', 2)

Screen Shot 2020-01-17 at 23 45 03

^This is the node output.

It is expandable and copy/pastable (where it wouldn't be if it was across multiple events).


Since console.log can be overloaded the naive solution is to push each console.log to CW however the problem is that this is rate-limited:

There is a quota of 5 requests per second per log stream. Additional requests are throttled. This quota can't be changed.

What you want to do is queue the log events up and PutLogEvents every second. The problem is that if you POST the queue after each event you may hit the rate-limit (since each event can be < 50ms) BUT if you don't then the process after each event they may never be POSTed (if the process is terminated) https://github.com/hayd/deno-lambda#warning


Ideally custom runtimes will have a local endpoint which manages such a CW logs batch queue... but nothing is documented as far as I can see.

OR it's even simpler and the newline can be encoded somehow (and still passed to stdout).

cc @brianleroux (perhaps you know / or know someone how has an answer for this)!

no such file or directory error (../runtime/mod.ts)

Hayd,

I followed your directions on using SAR as well as the ZIP based deploy for the deno-lambda hello.ts.

Each time I have this error where:

import {
APIGatewayProxyEventV2,
APIGatewayProxyResultV2,
Context,
} from "../runtime/mod.ts";

Is not resolving & is not found. Am I doing something wrong? Is the SAR deploy method not current? I was able to work around it when I loaded them into a new directory I created (copy / paste workaround), but I'm curious as to why I wasn't able to do it as you prescribed. Just want to make sure I am understanding your flow.

Thank you!
Screen Shot 2022-07-06 at 12 04 42 AM
Screen Shot 2022-07-06 at 12 06 49 AM

Serverless to run bundled js files

When using serverless to deploy bundled file dist.js, it was reporting that

START RequestId: 39dff4dd-6def-48d7-9830-52d5d8406efc Version: $LATEST
warn: unable to import '.deno_dir/' as DENO_DIR
error: Cannot resolve module "file:///var/task/dist.ts" from "file:///tmp/runtime.js"
�[0m�[1m�[31merror�[0m: Could not create TypeScript compiler cache location: "/home/sbx_user1051/.cache/deno/gen"
Check the permission of the directory.
error: bad deno executable
END RequestId: 39dff4dd-6def-48d7-9830-52d5d8406efc
REPORT RequestId: 39dff4dd-6def-48d7-9830-52d5d8406efc	Duration: 164.47 ms	Billed Duration: 200 ms	Memory Size: 1024 MB	Max Memory Used: 11 MB	
Unknown application error occurred
Unhandled

It looks like the module is assuming .ts files by default

1.x rc (and 1.x)

hey! wondering if you're planning on releasing updated bits to SAR? I'd rather re-use your work and get rid of mine!

Deno fails to start

I'm bundling my lambda with the recommended instructions

# Compile the handler (and cache dependencies and compile artifacts into DENO_DIR).
DENO_DIR=.deno_dir deno cache --import-map=import_map.json src/lambda.ts

# This is the "remapping" step:
cp -R .deno_dir/gen/file/$PWD/ .deno_dir/LAMBDA_TASK_ROOT
# Note: We do the inversew of this operation in bootstrap.

# First zip deno deps up
zip build/lambda.zip -x '.deno_dir/gen/file/*' -r .deno_dir

One interesting thing to note is that deno cache is producing files with double extensions

image

I've tried setting HANDLER_EXT = "ts.js, but I still encounter the following errors



2022-05-23T20:30:23.956-07:00 | error: Unable to load 'file:///var/task/import_map.json' import map
-- | --
  | 2022-05-23T20:30:23.956-07:00 | Caused by:
  | 2022-05-23T20:30:23.956-07:00 | No such file or directory (os error 2)
  | 2022-05-23T20:30:24.113-07:00Copyerror: missing expected handler file 'src/lambda.ts.js' | error: missing expected handler file 'src/lambda.ts.js'

The failure to transform DENO_IMPORTMAP = "./import_map.json" the way $LAMBDA_TASK_ROOT/$HANDLER_FILE is possibly a bug, but I don't think it is related.

More closely match Lambda behavior in tests/Dockerfile

These should match AWS Lambda uses for the function and the layers.
This will allow a more robust test for layer + function (to test the artifacts*).

Should we be using $SCRIPT_DIR rather than $LAMBDA_TASK_ROOT everywhere in bootstrap?

  • use https://deno.land/x/lambda in tests but fill that into DENO_DIR from runtime (we likely should do this in bootstrap too actually).
  • copy files into another directory in Dockerfile and before each test add specific files (this should be a key in .json in the test files, perhaps a second key for layer).
  • verify what happens in lambda if foo/hello.ts and foo/bar.ts is defined in the layer, and foo/hello.ts and foo/baz.ts is defined in the function. Which directories are they in. (This is important for DENO_DIR handling).
  • test context

Remaining from original issue but will handle separately.

  • add headers to invocation requests #7
  • test console logging inside a handler #8

Lambda container fails with extra file

Hi! Thank you for your great work!
I'm trying to build sample lambda with docker and I have a problem with extra file.

I tested a really simple example and I faced with following error.

❯ docker run -p 9000:8080 --rm deno-lambda:test
# ... after invocation via curl
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
time="2021-04-20T12:10:30.99" level=info msg="exec '/var/runtime/bootstrap' (cwd=/var/task, handler=)"
time="2021-04-20T12:10:32.738" level=info msg="extensionsDisabledByLayer(/opt/disable-extensions-jwigqn8j) -> stat /opt/disable-extensions-jwigqn8j: no such file or directory"
time="2021-04-20T12:10:32.74" level=warning msg="Cannot list external agents" error="open /opt/extensions: no such file or directory"
START RequestId: 2038c5d5-5185-4660-a33e-1eea3f6947f0 Version: $LATEST
warn: unable to import '.deno_dir/' as DENO_DIR
    at async file:///tmp/runtime.js:77:19h/26_fetch.js:844:19)
END RequestId: 2038c5d5-5185-4660-a33e-1eea3f6947f0
REPORT RequestId: 2038c5d5-5185-4660-a33e-1eea3f6947f0  Init Duration: 3.67 ms  Duration: 774.07 ms     Billed Duration: 800 ms Memory Size: 3008 MBMax Memory Used: 3008 MB

The project has just 3 files and each files are very simple.

hello.ts

import {
  APIGatewayProxyEventV2,
  APIGatewayProxyResultV2,
  Context,
} from "https://deno.land/x/lambda/mod.ts";
import { test } from "./lib.ts";

// deno-lint-ignore require-await
export async function handler(
  event: APIGatewayProxyEventV2,
  context: Context,
): Promise<APIGatewayProxyResultV2> {
  console.log(test());
  return {
    statusCode: 200,
    headers: { "content-type": "text/html;charset=utf8" },
    body: `Welcome to deno ${Deno.version.deno} 🦕`,
  };
}

lib.ts

export const test = () => {
  return "Fugafuga";
};

Dockerfile

FROM hayd/deno-lambda

COPY . .
RUN deno cache hello.ts

CMD ["hello.handler"]

Any suggestion for this?
I used current latest version 1.9 for base image

allow option to run with `--check`

Deno has a flag to run without type-checking, which is useful for lambdas that have already been type-checked. There are already several DENO ENV VARs to configure behavior, a DENO_NOCHECK or more flexible DENO_FLAGS would be useful here.

Possible to deploy with Pulumi?

I'm trying to give this lambda runtime a go on Pulumi, which should theoretically be similar to AWS-CDK but I'm not sure they support all the constructs necessary.

I can write something like:

const denoRuntime = await aws.serverlessrepository.getApplication({
    applicationId: "arn:aws:serverlessrepo:us-east-1:390065572566:applications/deno",
    semanticVersion: "1.16.0",
  });

To get the runtime application, but it's not clear if there's a way to actually create/clone this application and produce a layer ARN.

(Apologies for this pretty open support request, I'm kind of new to all of these tools)

"bad deno executable" after pre-handler error

The boostrap investigate function seems to handle pre-handler error's badly. I had uncaught exception during setup, and this showed up in the logs afterwards.

2020-11-17T13:27:33.673-08:00Copy�[0m�[1m�[31merror�[0m: Could not create TypeScript compiler cache location: "/home/sbx_user1051/.cache/deno/gen" | �[0m�[1m�[31merror�[0m: Could not create TypeScript compiler cache location: "/home/sbx_user1051/.cache/deno/gen"
-- | --
  | 2020-11-17T13:27:33.673-08:00 | Check the permission of the directory.
  | 2020-11-17T13:27:33.674-08:00 | error: bad deno executable

After fixing the error the lambda ran fine, so I don't think the deno executable is actually bad.

Add CI for bootstrap scripts

You could do this on amazon linux docker:

  1. start a server (which returns {"status": "OK"} on POSTs to /error and /response, and yield events on /next GET).
  2. set $AWS_LAMBDA_RUNTIME_API to localhost:port_of_server.
  3. run bootrap script.

Somehow use this for tests.

Edit: I have a first pass of this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.