Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from hayd/decrease-files
Browse files Browse the repository at this point in the history
Bump deno to 0.26.0
  • Loading branch information
hayd authored Dec 6, 2019
2 parents 21a38e9 + 720fa16 commit ee06c3f
Show file tree
Hide file tree
Showing 22 changed files with 54 additions and 56 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ From the [AWS console](https://console.aws.amazon.com/lambda/):

1. Download zip files from the [releases](https://github.com/hayd/deno-lambda/releases) page.

2. Create a _layer_ and upload `deno-lambda-layer.zip`. Note its ARN.
2. Create a _layer_ and upload `deno-lambda-layer.zip`.

<img width="828" alt="Create layer" src="https://user-images.githubusercontent.com/1931852/68455786-0b618100-01b1-11ea-988a-ba3a5810a8d5.png">

<img width="1122" alt="Layer created" src="https://user-images.githubusercontent.com/1931852/68455785-0b618100-01b1-11ea-9686-8ebefe3b00ff.png">

Note its Version ARN.

3. Create a lambda function from scratch with runtime "provide your own bootstrap".

<img width="1295" alt="Create function" src="https://user-images.githubusercontent.com/1931852/68455784-0ac8ea80-01b1-11ea-93ba-8c64a4e487e7.png">
Expand All @@ -32,7 +34,7 @@ From the [AWS console](https://console.aws.amazon.com/lambda/):

6. "Save". "Test" (use the default event).

<img width="1298" alt="Execution successful" src="https://user-images.githubusercontent.com/1931852/68455779-0ac8ea80-01b1-11ea-9204-67bf4cb1c250.png">
<img width="1277" alt="Execution successful" src="https://user-images.githubusercontent.com/1931852/70288824-bb61e400-1787-11ea-95a6-61bb3a260c05.png">

---

Expand Down Expand Up @@ -61,10 +63,11 @@ between invocations and will sometimes be shutdown.

```ts
export async function badHandler(event: Event, context: Context) {
somethingAsync() // not awaited
return
somethingAsync(); // not awaited
return;
}
```

If you need to return immediately but want to invoke a longer running process you can
[async-invoke](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html)
another lambda function (which does the `await somethingAsync()`).
Expand Down
13 changes: 7 additions & 6 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# Serverless example

Deploy in a single step using [`serverless deploy`](https://serverless.com/framework/docs/providers/aws/guide/deploying/).

This example lambda application defines:

- A lambda layer from the `deno-lambda-layer.zip`.
- A DynamodDB table "candidates".
- Three lambda functions a list/get/submit.
- An API Gateway endpoint to these functions.

This is based on [_Building a REST API in Node.js with AWS Lambda, API Gateway, DynamoDB, and Serverless Framework_ blogpost by Shekhar Gulat](https://serverless.com/blog/node-rest-api-with-serverless-lambda-and-dynamodb/).
Requires `deno-lambda-layer.zip` to be in the directory:

See the application described in `serverless.yml` and the exported functions in `api/candidate.ts`.
curl -sfL https://github.com/hayd/deno-lambda/releases/download/v0.4.0/deno-lambda-layer.zip -o deno-lambda-layer.zip

It can be deployed in a single step using [`serverless deploy`](https://serverless.com/framework/docs/providers/aws/guide/deploying/).
This example is based on [_Building a REST API in Node.js with AWS Lambda, API Gateway, DynamoDB, and Serverless Framework_ blogpost by Shekhar Gulat](https://serverless.com/blog/node-rest-api-with-serverless-lambda-and-dynamodb/).

Note: The `serverless-scriptable-plugin` is used to compile (`deno fetch api/candidate.ts`)
so there is no init-time download/compilation step.
See the application described in `serverless.yml` and the exported functions in `api/candidate.ts`.

DENO_DIR=.deno_dir deno fetch api/candidate.ts && cp -R .deno_dir/gen/file/$PWD/ .deno_dir/LAMBDA_TASK_ROOT
Note: The `serverless-scriptable-plugin` is used to compile `api/candidate.ts` so there is no init-time download/compilation step.

---

Expand Down
Binary file removed example/deno-lambda-layer.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion example/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export {
DynamoDBClient
} from "https://raw.githubusercontent.com/hayd/dynamodb/782f64ce64e7c83f964970c7eeacba0d5c9dfb91/mod.ts";

export { v4 as uuid } from "https://deno.land/std@v0.25.0/uuid/mod.ts";
export { v4 as uuid } from "https://deno.land/std@v0.26.0/uuid/mod.ts";
2 changes: 1 addition & 1 deletion example/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ provider:
name: aws
runtime: provided
stage: dev
region: us-east-1
region: ${env:AWS_DEFAULT_REGION, 'us-east-1'}
iamRoleStatements:
- Effect: "Allow"
Action:
Expand Down
4 changes: 2 additions & 2 deletions example/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
// You must also pass a access key/secret environment variables, but these don't have to be real e.g.
// AWS_ACCESS_KEY_ID=fakeMyKeyId AWS_SECRET_ACCESS_KEY=fakeSecretAccessKey deno --allow-env --allow-net test.ts

import { runIfMain } from "https://deno.land/std@v0.25.0/testing/mod.ts";
import { runIfMain } from "https://deno.land/std@v0.26.0/testing/mod.ts";
import {
assert,
assertEquals
} from "https://deno.land/std@v0.25.0/testing/asserts.ts";
} from "https://deno.land/std@v0.26.0/testing/asserts.ts";

import { client } from "./client.ts";
import { test } from "./test_util.ts";
Expand Down
2 changes: 1 addition & 1 deletion example/test_util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
TestDefinition,
test as stdTest
} from "https://deno.land/std@v0.25.0/testing/mod.ts";
} from "https://deno.land/std@v0.26.0/testing/mod.ts";

import { client } from "./client.ts";
import { TableName } from "./api/candidate.ts";
Expand Down
6 changes: 0 additions & 6 deletions runtime/Dockerfile

This file was deleted.

6 changes: 3 additions & 3 deletions runtime/artifacts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ cp -R .deno_dir/gen/file/$PWD/. .deno_dir/LAMBDA_TASK_ROOT
zip -qq deno-lambda-layer.zip -x '.deno_dir/gen/file/*' -r .deno_dir amz-deno bootstrap hello.ts
zip -qq deno-lambda-example.zip -x '.deno_dir/gen/file/*' -r .deno_dir hello.ts

DENO_DIR=.deno_dir ./amz-deno bundle bundle.ts bundle.bundle.js
DENO_DIR=.deno_dir ./amz-deno bundle hello.ts hello.bundle.js

rm -rf .deno_dir
mkdir -p .deno_dir/deps/https/deno.land/x/lambda/
cp mod.ts .deno_dir/deps/https/deno.land/x/lambda/mod.ts
DENO_DIR=.deno_dir ./amz-deno fetch remote.ts
DENO_DIR=.deno_dir ./amz-deno fetch pad.ts
cp -R .deno_dir/gen/file/$PWD/. .deno_dir/LAMBDA_TASK_ROOT
zip -qq remote.zip -x '.deno_dir/gen/file/*' -r .deno_dir remote.ts
zip -qq pad.zip -x '.deno_dir/gen/file/*' -r .deno_dir pad.ts
7 changes: 3 additions & 4 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Note: This must be built in the .. context

FROM hayd/deno:amazonlinux1-0.25.0
FROM hayd/deno:amazonlinux1-0.26.0
# This is the runtime used by AWS Lambda
# plus a compatible deno executable /bin/deno.
# https://github.com/hayd/deno_docker
Expand All @@ -27,13 +27,12 @@ RUN deno fetch /src/tests/deps.ts

ADD hello.ts /src/runtime/hello.ts
ADD hello.ts /src/tests/hello.ts
ADD tests/bundle.ts /src/runtime/bundle.ts
ADD tests/remote.ts /src/runtime/remote.ts
ADD tests/pad.ts /src/runtime/pad.ts
ADD runtime /src/runtime

WORKDIR /src/runtime
RUN sh artifacts \
&& cp bundle.bundle.js /src/tests/bundle.bundle.js \
&& cp hello.bundle.js /src/tests/hello.bundle.js \
&& cp bootstrap /src/tests/bootstrap

WORKDIR /src/tests
Expand Down
1 change: 0 additions & 1 deletion tests/bundle.ts

This file was deleted.

6 changes: 3 additions & 3 deletions tests/deps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { assertEquals } from "https://deno.land/std@v0.25.0/testing/asserts.ts";
export { serve } from "https://deno.land/std@v0.25.0/http/server.ts";
export { runIfMain, test } from "https://deno.land/std@v0.25.0/testing/mod.ts";
export { assertEquals } from "https://deno.land/std@v0.26.0/testing/asserts.ts";
export { serve } from "https://deno.land/std@v0.26.0/http/server.ts";
export { runIfMain, test } from "https://deno.land/std@v0.26.0/testing/mod.ts";
1 change: 0 additions & 1 deletion tests/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export async function foo(event: Event, context: Context) {
}

export async function withContext(event: Event, context: Context) {
// is there a foo attribute?! who knows!
return { name: context.functionName, awsRequestId: context.awsRequestId };
}

Expand Down
9 changes: 9 additions & 0 deletions tests/pad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Context, Event } from "https://deno.land/x/lambda/mod.ts";
// pad.ts is chosen since it has no dependencies.
// i.e. we must download precisely one file from deno.land.
import { pad } from "https://deno.land/std/strings/pad.ts";

export function handler(event: Event, context: Context) {
const strLen: number = Number(event.strLen) || 5;
return pad("deno", strLen);
}
6 changes: 0 additions & 6 deletions tests/remote.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tests/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function bootstrap(testJson) {
return Deno.run({
args: [bootstrapScript],
stdout: "piped",
// stderr: "piped", // comment this out to debug
stderr: "piped", // comment this out to debug
env: testJson.env,
cwd: "/var/task"
});
Expand Down
8 changes: 4 additions & 4 deletions tests/test_bundle.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"env": {
"_HANDLER": "bundle.handler",
"_HANDLER": "hello.handler",
"HANDLER_EXT": "bundle.js"
},
"events": [{ "hello": "deno" }, { "hello": "again" }],
"expected": [
{
"status": "ok",
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.25.0 🦕\"}"
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.26.0 🦕\"}"
},
{
"status": "ok",
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.25.0 🦕\"}"
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.26.0 🦕\"}"
}
],
"files": ["bundle.bundle.js"],
"files": ["hello.bundle.js"],
"layer": "deno-lambda-layer.zip"
}
8 changes: 4 additions & 4 deletions tests/test_denodir.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"env": {
"_HANDLER": "remote.handler"
"_HANDLER": "pad.handler"
},
"events": [{ "hello": "deno" }, { "hello": "again" }],
"events": [{ "hello": "deno" }, { "strLen": "6" }],
"expected": [
{
"status": "ok",
"content": "\" deno\""
},
{
"status": "ok",
"content": "\" deno\""
"content": "\" deno\""
}
],
"files": "remote.zip",
"files": "pad.zip",
"layer": "deno-lambda-layer.zip"
}
4 changes: 2 additions & 2 deletions tests/test_example_zip.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"expected": [
{
"status": "ok",
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.25.0 🦕\"}"
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.26.0 🦕\"}"
},
{
"status": "ok",
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.25.0 🦕\"}"
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.26.0 🦕\"}"
}
],
"files": "deno-lambda-example.zip",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_js.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"expected": [
{
"status": "ok",
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.25.0 🦕\"}"
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.26.0 🦕\"}"
},
{
"status": "ok",
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.25.0 🦕\"}"
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.26.0 🦕\"}"
}
],
"files": ["hello.js"],
Expand Down
4 changes: 2 additions & 2 deletions tests/test_self_contained.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"expected": [
{
"status": "ok",
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.25.0 🦕\"}"
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.26.0 🦕\"}"
},
{
"status": "ok",
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.25.0 🦕\"}"
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.26.0 🦕\"}"
}
],
"files": ["hello.ts", "bootstrap", "amz-deno"]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"expected": [
{
"status": "ok",
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.25.0 🦕\"}"
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.26.0 🦕\"}"
},
{
"status": "ok",
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.25.0 🦕\"}"
"content": "{\"statusCode\":200,\"body\":\"Welcome to deno 0.26.0 🦕\"}"
}
],
"files": ["hello.ts"],
Expand Down

0 comments on commit ee06c3f

Please sign in to comment.