Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation nit: Serverless functions #3550

Open
orta opened this issue Oct 11, 2021 · 6 comments
Open

Documentation nit: Serverless functions #3550

orta opened this issue Oct 11, 2021 · 6 comments
Labels
bug/needs-info More information is needed for reproduction topic/api

Comments

@orta
Copy link
Contributor

orta commented Oct 11, 2021

A question I kinda wanted https://redwoodjs.com/docs/serverless-functions to answer: Why do the generated files from the serverless generator seem to tie to aws?

( I think I know the answer is that in general aws-lambda's API style must be the default for many other cloud providers but it wasn't on vercel + next's nor azure's which I at least have some experience with. Figured the docs would have the answer there. )

Related, perhaps yarn rw g functions can check for @types/aws-lambda in node_modules and recommend it when in TypeScript mode? The IDE doesn't show errors that it's missing (it just any'd) and installing aws-lambda doesn't include those types (because it's a different module). Ideally Redwood could inline the APIGatewayEvent types into @redwoodjs/api/webhooks instead then use those.

@thedavidprice
Copy link
Contributor

Background

Looping in @dthyresson for a better explanation about this. The short version is that:

  • this is legacy based on the early use of Apollo Server and Netlify deploy target (which uses AWS Lambdas)
  • we intend to make this all agnostic in the future

The important first step (and massive lift) was migrating the GraphQL server to Envelop/Helix, which is still AWS Lambda but can now be made agnostic. The functions have been a secondary priority

Next Step

It seems like there's some buggy behavior we need to diagnose and resolve near-term, regardless of how we make any/all functions provider agnostic in the future.

@dthyresson
Copy link
Contributor

dthyresson commented Oct 18, 2021

@cannikin Does the new generator template also support function templates? If so, then we could keep the function templates with aws -- since the api-server relies on that but then for deploy one could use another template with req, res or other handlers.

Edit:

Looks like it does:

const SIDE_MAP = {
  web: ['cell', 'component', 'layout', 'page', 'scaffold'],
  api: ['function', 'sdl', 'service'],

@dthyresson
Copy link
Contributor

That said, the core issue is that the api-server which is also used in dev to serve functions relies on

import type { Handler } from 'aws-lambda'

import type { Handler } from 'aws-lambda'

@dthyresson
Copy link
Contributor

Related, perhaps yarn rw g functions can check for @types/aws-lambda in node_modules and recommend it when in TypeScript mode? The IDE doesn't show errors that it's missing (it just any'd) and installing aws-lambda doesn't include those types (because it's a different module). Ideally Redwood could inline the APIGatewayEvent types into @redwoodjs/api/webhooks instead then use those.

Oh, I see. Ok, I need to think on this a little.

Should we:

  • fix the AWS types issue (just)
  • try to make the function more flexible and not rely on AWS (and is this @thedavidprice 1.0)

@cannikin
Copy link
Member

It does! yarn rw setup generator function will give you the template and can change up whatever you want. Are you thinking that if you yarn rw setup deploy that it might also run yarn rw setup template function --vercel or something similar, so that any future functions you generate will use a template customized for that host?

It doesn't currently have the ability to pass flags and select from other templates, but I don't see why it couldn't...

@dthyresson
Copy link
Contributor

Are you thinking that if you yarn rw setup deploy that it might also run yarn rw setup template function --vercel or something similar, so that any future functions you generate will use a template customized for that host?

That's an interesting thought. 🤔

@jtoar jtoar removed this from the future-release milestone Dec 11, 2021
@jtoar jtoar removed the v1/priority label May 6, 2022
@dthyresson dthyresson removed their assignment Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/needs-info More information is needed for reproduction topic/api
Projects
Status: Backlog
Development

No branches or pull requests

5 participants