Skip to content

Commit

Permalink
Merge pull request #115 from hayd/amazonlinux2
Browse files Browse the repository at this point in the history
Update provided runtime to al2
  • Loading branch information
hayd committed Dec 17, 2020
2 parents f826431 + e834861 commit 2c5ef70
Show file tree
Hide file tree
Showing 44 changed files with 215 additions and 182 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ jobs:
docker run test-runner
- name: Extract artifacts
run: |
docker cp extract:/bin/deno amz-deno
docker cp extract:/src/runtime/deno-lambda-layer.zip deno-lambda-layer.zip
docker cp extract:/src/runtime/deno-lambda-example.zip deno-lambda-example.zip
gzip -9 amz-deno
test_example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: denolib/setup-deno@master
with:
deno-version: 1.6.0
deno-version: 1.6.1
- name: start a local dynamodb
run: |
mkdir dyno
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/fmt_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: denolib/setup-deno@master
with:
deno-version: 1.6.0
- name: Run fmt
run: |
deno fmt --check
- name: Run lint
run: |
deno lint --unstable hello.ts tests
deno lint --unstable examples-aws-cdk
deno lint --unstable example-sam --ignore=example-sam/.aws-sam
deno lint --unstable example-serverless --ignore=example-serverless/node_modules,example-serverless/.deno_dir
3 changes: 0 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ jobs:
docker run test-runner
- name: Extract artifacts
run: |
docker cp extract:/bin/deno amz-deno
docker cp extract:/src/runtime/deno-lambda-layer.zip deno-lambda-layer.zip
docker cp extract:/src/runtime/deno-lambda-example.zip deno-lambda-example.zip
gzip -9 amz-deno
- name: Verify Release Version Matches Deno Version
if: startsWith(github.ref, 'refs/tags/') && github.repository == 'hayd/deno-lambda'
run: |
Expand All @@ -31,7 +29,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
amz-deno.gz
deno-lambda-layer.zip
deno-lambda-example.zip
draft: true
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.serverless
node_modules
package-lock.json
*.zip
*.zip
example-sam/.aws-sam/*
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ 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 hello.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:

```sh
# 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 hello.handler
$ 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:
Expand Down
2 changes: 1 addition & 1 deletion SAR/blueprint/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Resources:
Key: deno-lambda-example_DENO_LAMBDA_VERSION.zip
MemorySize: 128
Handler: hello.handler
Runtime: provided
Runtime: provided.al2
Layers:
- !GetAtt Deno.Outputs.LayerArn
Events:
Expand Down
2 changes: 1 addition & 1 deletion example-aws-cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ cdk deploy

---

[Example borrowed from AWS-SAMPLES](https://github.com/aws-samples/aws-cdk-examples/blob/master/typescript/lambda-api-ci/lib/lambda-api-stack.ts)
[Example borrowed from AWS-SAMPLES](https://github.com/aws-samples/aws-cdk-examples/blob/master/typescript/lambda-api-ci/lib/lambda-api-stack.ts)
8 changes: 4 additions & 4 deletions example-aws-cdk/bin/example-aws-cdk.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from '@aws-cdk/core';
import { ExampleAwsCdkStack } from '../cdk/example-aws-cdk-stack';
import "source-map-support/register";
import * as cdk from "@aws-cdk/core";
import { ExampleAwsCdkStack } from "../cdk/example-aws-cdk-stack";

const app = new cdk.App();
new ExampleAwsCdkStack(app, 'ExampleAwsCdkStack');
new ExampleAwsCdkStack(app, "ExampleAwsCdkStack");
57 changes: 30 additions & 27 deletions example-aws-cdk/cdk/example-aws-cdk-stack.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
import * as cdk from '@aws-cdk/core';
import * as lambda from '@aws-cdk/aws-lambda';
import * as apigw from '@aws-cdk/aws-apigateway';
import { CfnApplication } from '@aws-cdk/aws-sam'
import * as cdk from "@aws-cdk/core";
import * as lambda from "@aws-cdk/aws-lambda";
import * as apigw from "@aws-cdk/aws-apigateway";
import { CfnApplication } from "@aws-cdk/aws-sam";

export class ExampleAwsCdkStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const denoRuntime = new CfnApplication(this, "DenoRuntime", {
location: {
applicationId:
"arn:aws:serverlessrepo:us-east-1:390065572566:applications/deno",
semanticVersion: "1.6.1",
},
});

const denoRuntime = new CfnApplication(this, 'DenoRuntime', {
location: {
applicationId: 'arn:aws:serverlessrepo:us-east-1:390065572566:applications/deno',
semanticVersion: '1.6.0'
}
});
// Deno Layer
const layer = lambda.LayerVersion.fromLayerVersionArn(
this,
"denoRuntimeLayer",
denoRuntime.getAtt("Outputs.LayerArn").toString(),
);

// Deno Layer
const layer = lambda.LayerVersion.fromLayerVersionArn(this, 'denoRuntimeLayer', denoRuntime.getAtt('Outputs.LayerArn').toString())
const name = new lambda.Function(this, "HelloHandler", {
runtime: lambda.Runtime.PROVIDED_AL2,
code: lambda.Code.fromAsset("src"),
handler: "hello.handler",
layers: [layer],
});

const name = new lambda.Function(this, 'HelloHandler', {
runtime: lambda.Runtime.PROVIDED,
code: lambda.Code.fromAsset('src'),
handler: 'hello.handler',
layers: [layer],
})

// API Gateway
new apigw.LambdaRestApi(this, 'Endpoint', {
handler: name
});

}
// API Gateway
new apigw.LambdaRestApi(this, "Endpoint", {
handler: name,
});
}
}
22 changes: 11 additions & 11 deletions example-aws-cdk/src/hello.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {
APIGatewayProxyEvent,
APIGatewayProxyResult,
Context
APIGatewayProxyEvent,
APIGatewayProxyResult,
Context,
} from "https://deno.land/x/lambda/mod.ts";

export async function handler(
event: APIGatewayProxyEvent,
context: Context,
event: APIGatewayProxyEvent,
context: Context,
): Promise<APIGatewayProxyResult> {
return {
statusCode: 200,
headers: { "content-type": "text/html;charset=utf8" },
body: `Hello World! Sent from AWS CDK deno ${Deno.version.deno} 🦕`,
};
}
return {
statusCode: 200,
headers: { "content-type": "text/html;charset=utf8" },
body: `Hello World! Sent from AWS CDK deno ${Deno.version.deno} 🦕`,
};
}
3 changes: 2 additions & 1 deletion example-sam/hello.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
APIGatewayProxyEvent,
APIGatewayProxyResult,
Context
Context,
} from "https://deno.land/x/lambda/mod.ts";

// deno-lint-ignore require-await
export async function handler(
event: APIGatewayProxyEvent,
context: Context,
Expand Down
4 changes: 2 additions & 2 deletions example-sam/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ Resources:
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:us-east-1:390065572566:applications/deno
SemanticVersion: 1.6.0
SemanticVersion: 1.6.1

HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
MemorySize: 128
Handler: hello.handler
Runtime: provided
Runtime: provided.al2
Layers:
- !GetAtt Deno.Outputs.LayerArn
Events:
Expand Down
12 changes: 6 additions & 6 deletions example-serverless/api/candidate.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import {
APIGatewayProxyEvent,
Context
Context,
} from "https://deno.land/x/lambda/mod.ts";

import { client } from "../client.ts";
import { Doc, uuid } from "../deps.ts";

export const TableName = "candidates";

function ok(body: any, statusCode: number = 200) {
function ok(body: unknown, statusCode = 200) {
return {
statusCode,
body: JSON.stringify(body),
};
}
function error(message: string, statusCode: number = 500) {
function error(message: string, statusCode = 500) {
return ok({ message: message }, statusCode);
}

Expand Down Expand Up @@ -48,7 +48,7 @@ export async function list(event: APIGatewayProxyEvent, context: Context) {
TableName,
ProjectionExpression: "id, fullname, email",
};
let result: any;
let result: unknown;
try {
result = await client.scan(params);
} catch (e) {
Expand All @@ -58,11 +58,11 @@ export async function list(event: APIGatewayProxyEvent, context: Context) {
// FIXME better way to handle this??
const items = [];
try {
for await (const page of result) {
for await (const page of result as AsyncIterableIterator<Doc>) {
items.push(...page.Items);
}
} catch {
items.push(...result.Items);
items.push(...(result as Doc).Items);
}
return ok({ candidates: items });
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion example-serverless/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { DynamoDBClient, createClient } from "./deps.ts";
import { createClient, DynamoDBClient } from "./deps.ts";

export const client: DynamoDBClient = createClient();
2 changes: 1 addition & 1 deletion example-serverless/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export type {
DynamoDBClient,
} from "https://raw.githubusercontent.com/chiefbiiko/dynamodb/8d7cd9f1c7ce028dbf0ad15d6b90665e40d30953/mod.ts";

import { v4 } from "https://deno.land/std@0.77.0/uuid/mod.ts";
import { v4 } from "https://deno.land/std@0.80.0/uuid/mod.ts";
export const uuid = v4.generate;
4 changes: 2 additions & 2 deletions example-serverless/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ frameworkVersion: ">=1.1.1 <2.0.0"

provider:
name: aws
runtime: provided
runtime: provided.al2
stage: dev
region: ${env:AWS_DEFAULT_REGION, 'us-east-1'}
iamRoleStatements:
Expand Down Expand Up @@ -64,7 +64,7 @@ resources:
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:us-east-1:390065572566:applications/deno
SemanticVersion: 1.6.0
SemanticVersion: 1.6.1

candidatesTable:
Type: AWS::DynamoDB::Table
Expand Down
8 changes: 4 additions & 4 deletions example-serverless/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
// 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 AWS_DEFAULT_REGION=local deno run --allow-env --allow-net

import { assertEquals } from "https://deno.land/std@0.77.0/testing/asserts.ts";
import { assertEquals } from "https://deno.land/std@0.80.0/testing/asserts.ts";
import {
APIGatewayProxyEvent,
Context
Context,
} from "https://deno.land/x/lambda/mod.ts";

import { client } from "./client.ts";
import { test } from "./test_util.ts";
import {
list as listCandidate,
get as getCandidate,
list as listCandidate,
submit as submitCandidate,
TableName
TableName,
} from "./api/candidate.ts";

test({
Expand Down
3 changes: 2 additions & 1 deletion hello.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
APIGatewayProxyEvent,
APIGatewayProxyResult,
Context
Context,
} from "https://deno.land/x/lambda/mod.ts";

// deno-lint-ignore require-await
export async function handler(
event: APIGatewayProxyEvent,
context: Context,
Expand Down
4 changes: 2 additions & 2 deletions runtime/artifacts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ DENO_DIR=/src/runtime/.deno_dir ./bin/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=/src/runtime/.deno_dir ./bin/deno cache pad.ts
DENO_DIR=/src/runtime/.deno_dir ./bin/deno cache lock.ts
cp -R .deno_dir/gen/file/$PWD/. .deno_dir/LAMBDA_TASK_ROOT
zip -qq pad.zip -x '.deno_dir/gen/file/*' -r .deno_dir pad.ts
zip -qq lock.zip -x '.deno_dir/gen/file/*' -r .deno_dir lock.ts

0 comments on commit 2c5ef70

Please sign in to comment.