#anyone have a modern container workflow for the serverless framework?

11 messages · Page 1 of 1 (latest)

open salmon
#

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.

#

Gpt was rabbit holing into irrelevant nonsense

open salmon
#

Specifically getting it working with serverless framework ; the terminology in this space is HORRENDOUS

sharp umbra
#

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 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

A deno runtime for AWS Lambda. Deploy deno via docker, SAM, serverless, or bundle it yourself. - hayd/deno-lambda

#

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

open salmon
#

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

sharp umbra
#

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;

Define Dockerfile

//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 };