wungobungo
wungobungo13mo ago

anyone have a modern container workflow for the serverless framework?

I was able to find code that executed at one point in time. It no longer does. I’d really like to instead get fresh or deno into a container and use serverless to make it work on aws. this is at least as of current a requirement for all code at my workplace and is a hard must to hit production with deno.
9 Replies
wungobungo
wungobungo13mo ago
Gpt was rabbit holing into irrelevant nonsense
wungobungo
wungobungo13mo ago
Specifically getting it working with serverless framework ; the terminology in this space is HORRENDOUS
fro.profesional
fro.profesional13mo ago
You can use the image and docker file to deploy using Serverless framework http://serverless.com//blog/container-support-for-lambda https://github.com/hayd/deno-lambda/tree/master/example-serverless We usted to have deno api running on AWS LAMBDA with the combination of this articles and a more simplier Serverless yml
Container Image Support for AWS Lambda
Container Image Support for AWS Lambda has now been added. Read up on why you may (or may not) want to use it and how easy it is to use with the framework
GitHub
deno-lambda/example-serverless at master · hayd/deno-lambda
A deno runtime for AWS Lambda. Deploy deno via docker, SAM, serverless, or bundle it yourself. - hayd/deno-lambda
fro.profesional
fro.profesional13mo ago
Give it a read to the repository and the article it was pretty simple, we moved to deno deploy due the lower cold starts, thats why currently i dont have an example, let me know if u cant to try to setup a basic example
wungobungo
wungobungo13mo ago
Unfortunately I have a codified requirement to utilize serverless for 100% of AWS infra at my company 😭 There’s hardline requirements for access to internal networks no meshing nothing allowed
fro.profesional
fro.profesional13mo ago
I did find and old test trying to use OAK https://github.com/fro-profesional/POC/tree/main/aws-deno
GitHub
POC/aws-deno at main · fro-profesional/POC
Proof of concept. Quick test of different things. Contribute to fro-profesional/POC development by creating an account on GitHub.
fro.profesional
fro.profesional13mo ago
Let me know if it helps But in short: Define serverless.yml | .ts | .js
// serverless.js (you can use yml also)
const name = "deno-lambda-test";
let config = {
service: name,
provider: {
name: "aws",
ecr: { images: { [name]: { path: "./" } } },
},
functions: {
service: {
image: { name },
events: [{ httpApi: "*" }],
},
},
};
module.exports = config;
// serverless.js (you can use yml also)
const name = "deno-lambda-test";
let config = {
service: name,
provider: {
name: "aws",
ecr: { images: { [name]: { path: "./" } } },
},
functions: {
service: {
image: { name },
events: [{ httpApi: "*" }],
},
},
};
module.exports = config;
Define Dockerfile
//Dockerfile
FROM hayd/deno-lambda:1.29.1

COPY . .
RUN deno cache lambda.ts

CMD ["lambda.handler"]
//Dockerfile
FROM hayd/deno-lambda:1.29.1

COPY . .
RUN deno cache lambda.ts

CMD ["lambda.handler"]
Define handler
//lambda.ts
import {
APIGatewayProxyEventV2,
APIGatewayProxyResultV2,
Context,
} from "https://deno.land/x/lambda@1.28.3/mod.ts";

const handler = async (
event: APIGatewayProxyEventV2,
context: Context
): Promise<APIGatewayProxyResultV2> => {

return {
body: JSON.stringify({
message: "hello-world"
}),
headers: {
"content-type": "application/json",
"Access-Control-Allow-Origin": "*",
},
statusCode: 200,
};
};

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

const handler = async (
event: APIGatewayProxyEventV2,
context: Context
): Promise<APIGatewayProxyResultV2> => {

return {
body: JSON.stringify({
message: "hello-world"
}),
headers: {
"content-type": "application/json",
"Access-Control-Allow-Origin": "*",
},
statusCode: 200,
};
};

export { handler };
wungobungo
wungobungo13mo ago
thanks! this is what I was looking for