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

feat: Hosting / AWS Lambda / Serverless Framework #338

Closed
wants to merge 29 commits into from

Conversation

aheissenberger
Copy link
Contributor

#335

currently supports:

  • create a Hono / AWS Lambda Handler
  • Provide a basic setup:
    • s3 bucket for all static content from dist/client/assets
    • lambda with the server code
    • Cloudfront CDN to route /assets to the s3 bucket and all other requests to the lambda
    • invalidate the CDN cache on deployment

@aheissenberger
Copy link
Contributor Author

@magne4000 Thank you for your Feedback - do you need more changes?

@aheissenberger
Copy link
Contributor Author

I have a question related to the template functions $README.md.ts. I would like to use this to manipulate a yaml file but there is no reader for yaml and I am not allowed to import any other packages. I know I can embed the yaml in a string and manipulate the string, but I would prefer to read an existing yaml file, convert it to json and than export it again back to yaml.

@magne4000
Copy link
Member

I have a question related to the template functions $README.md.ts. I would like to use this to manipulate a yaml file but there is no reader for yaml and I am not allowed to import any other packages. I know I can embed the yaml in a string and manipulate the string, but I would prefer to read an existing yaml file, convert it to json and than export it again back to yaml.

I created a new loadYaml util. It's untested but fairly simple. If you need to update/fix it, it shouldn't be too difficult.

@magne4000 Thank you for your Feedback - do you need more changes?

I don't think so. I just need to try it out before merging :)

@aheissenberger
Copy link
Contributor Author

How to run a specific pnpm test:e2e - I have added one and would like to only run this test e.g. FRAMEWORK+aws-lambda-serverless.spec.ts

@phonzammi
Copy link
Member

@aheissenberger, pnpm run test:e2e --filter solid,express

Copy link
Member

@magne4000 magne4000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not comment on each code related to Sentry, but the goal is to have Sentry code related to itself in its own sentry boilerplate.

We should be able to integrate Sentry independently from serverless if needed.

boilerplates/aws-lambda-serverless/files/$.env.ts Outdated Show resolved Hide resolved
boilerplates/aws-lambda-serverless/files/$package.json.ts Outdated Show resolved Hide resolved
@aheissenberger
Copy link
Contributor Author

@magne4000 the problem with the e2e test failing sometimes but not allways is not related to this changes
pnpm run test:e2e --keep --summarize --filter solid --steps build,test
I had this error also on my macOS system.

@magne4000
Copy link
Member

Yes it sometimes happens due to some temp files being created, I usually just rerun the test manually.

@magne4000 magne4000 marked this pull request as draft August 22, 2024 12:48
@@ -12,5 +19,41 @@ export default async function getViteConfig(props: TransformerProps) {
options: reactOptions,
});

if (props.meta.BATI.has("sentry")) {
// load app level environment variables from `.env` file
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@magne4000 I currently stuck with transforming existing vite.config code. Have a look at my code maybe you can help me to solve this.
An alternative solution would be, that the wrapper exists in the default function. I had to change the exports in packages/core/src/magicast.ts to access the needed functions to manipulate the AST.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change the exports in packages/core/src/magicast.ts to access the needed functions to manipulate the AST.

👍 no issue with that

An alternative solution would be, that the wrapper exists in the default function

I already tried that, but magicast doesn't support this syntax sadly, so even if you could generate one, further $vite.config.ts.ts wouldn't be able to parse it.

When faced with the same problem last time, my solution was to use process.ENV instead of mode so I can avoid creating the function.
Then complex manipulations where directly done in original vite.config.ts.

@magne4000
Copy link
Member

@aheissenberger Please be sure to toggle this PR back to "Ready for review" once you consider I can review it again and test it.

@aheissenberger
Copy link
Contributor Author

@aheissenberger Please be sure to toggle this PR back to "Ready for review" once you consider I can review it again and test it.

I have restarted with this:

  1. I have replaced the Serverless Framework with the AWS CDK - one of the reason is, that die new 4.x Version is no longer open source for companies with more than 2 Mio revenue
  2. will create an extra pull request for sentry react

How would you suggest to modle this requirement:

  1. there are multiple targets to deploy on AWS: AWS Lambda, Lambda@Edge which need different Wrappers for Hono,..
  2. there are multiple ways to create the requires infrastructure on AWS and deploy: AWS CDK, Serverless Framework, SST.dev, ...

My current idea is:

  1. a feature called aws-lambda which will add the wrapper to hono, hatip,..
  2. a feature called aws-cdk which provides a sample configuration to deploy to AWS

@aheissenberger
Copy link
Contributor Author

With Universal Middleware directly supporting AWS Lambda there would be no need to add one of the serverless server frameworks like hono or hattip.

@magne4000
Copy link
Member

there are multiple targets to deploy on AWS: AWS Lambda, Lambda@Edge which need different Wrappers for Hono

If possible, we just edit hono-entry.ts. If that's too complex, let's just create other wrapper files like hono-entry-aws-edge.ts.
I would suggest to choose just one at first, to limit the scope of the PR. That way I'll also be able to improve Bati's internal for future requirements

there are multiple ways to create the requires infrastructure on AWS and deploy: AWS CDK, Serverless Framework, SST.dev, ...

Same as above, choose one for now. This adds a lot of complexity to supports multiple of those I feel.

a feature called aws-lambda which will add the wrapper to hono, hatip,..
a feature called aws-cdk which provides a sample configuration to deploy to AWS

My goal is to have features with options soon for this kind of use cases. Usage would be: pnpm create bati --react --aws=lambda,cdk. I'll prioritize this. But for now, if we choose only CDK and Lamda, we can avoid creating another feature. Just put both in aws feature for now.

@magne4000
Copy link
Member

With Universal Middleware directly supporting AWS Lambda there would be no need to add one of the serverless server frameworks like hono or hattip.

It will not be straightforward to implement (in universal-middleware) and integrate (in bati), so you can assume that you will probably have finished this PR before I had time to properly support all this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants