Deploying to AWS Lambda

What does it take to deploy the redwood api part to AWS Lambda directly? I would like to take a shot at it.

2 Likes

I had the same question until a few minutes ago. Unless I have misunderstood something, the /api functions are automatically created as Netlify Functions, that are powered by AWS Lambda. See Netlify docs and how they correspond to the paths in Redwood: https://docs.netlify.com/functions/build-with-javascript/#format

So as soon as you deploy to Netlify, you have deployed to AWS as well.

1 Like

We currently rely on Netlify to do the heavy lifting of deployment for us, but we intend to make it easy to write deployment providers that will allow deployment to a wide variety of services. Can you explain a bit more about what setup you’d like to deploy to so we can make sure to consider it? Also, if you had time to explore code to do that deployment, we would love the help and it would speed things up!

1 Like

As for AWS Lambda via Netlify, you are correct that they only deploy them to us-east. This is an area where we are seeking improvement, to allow you to choose your level of global distribution with simple config.

1 Like

Redwood has it’s own build command, which by default builds for both sides: api and web. But you can run yarn rw build web and yarn rw build api separately. Effectively you can use the yarn rw build api command to deploy manually/directly. See the doc referenced below for more info about what’s happening when you deploy to Netlify:

With some webpack changes, I made a deployment of the api to AWS lambda directly. Will open a issue/PR to review the changes.

1 Like

The below prisma2 issue seems to affect deploying directly to AWS lambda too.

Ah, likely you’ll need to setup step 2 “deploy build” on the AWS Lambda side of things. Not my expertise at all. I just know @rob did some specific work with Netlify build to make sure the deploy to AWS Lambda worked correctly. This is why we use the Netlify “beta build” enabled for RedwoodJS. It would be tedious, but try looking through the build process Netlify runs for Redwood.

Any thoughts to this end, @rob?

1 Like

@Jaikant This sounds like where you have to manually tell Prisma the proper binary to use. It means updating schema.prisma to look like:

generator client {
  provider = "prisma-client-js"
  binaryTargets = ["native", "rhel-openssl-1.0.x"]
}

native makes sure the proper ones are still loaded for your local development, rhel-openssl-1.0.x is what’s needed for Lambda.

3 Likes

@rob I had set the binary target to rhel-openssl-1.0.x, It seems the issue got introduced between preview025 and beta.1 of prisma.

So I got the api part deployed and working on AWS lambda directly using serverless. I had to move some files around in the dist directory and also set the environment variables in AWS. I shall create an issue to discuss the changes.

2 Likes