sladg / nextjs-lambda

Lambda deployments for Nextjs12 & Nextjs13 (standalone). Easy CLI commands to get your standalone Next output to run in AWS Lambda (not @Edge)! Uses CDK in behind and produces code zips importable to Terraform, Serverless, Azure, etc.
MIT License
169 stars 19 forks source link

CDK Additional Information #47

Closed judemanutd closed 1 year ago

judemanutd commented 1 year ago

Hey @sladg great library and this isn't really an issue as such, it's just more of an information gathering question.

I ran the commands that were mentioned and the app was definitely deployed but I'm not really familiar with CDK and that's kind of where my question lies.

Initially, I ran into an issue with the deploy command not being able to find the environment variables so that led me to installing cdk and running cdk bootstrap and that solved the issue as I was able to point it to the correct profile, account and region.

So my question is, is there a way I can configure AWS related attributes like the name of the Cloudfront resource or associating a domain with the Cloudfront distribution. This might be a CDK related question but I just wanted to drop it here to confirm that. I can indeed see CDK related config in the cdk.out folder and my guess is that editing the data there should help with this.

sladg commented 1 year ago

Hey @judemanutd!

Soo, to answer first part (and I will probably update the README a bit to be more CDK-beginner friendly), you can use --bootstrap flag with deploy command which will make it easier for first-time deployment without bootstrapped env.

Secondly, in terms of changing resource names, etc. all the names are derived from StackName which you can specify as you see fit, in case you need more granular access, I would suggest copying my CDK code and modifying it. I don't expect 90% of people to need this so I would rather keep it simple out-of-the-box than provide excessive amount of configuration.

In case something needs to be modified, I have included some output values in Cloudformation stack, those can be accessed and further modified outside of the CDK script. See: https://stackoverflow.com/questions/41628487/getting-outputs-from-aws-cloudformation-describe-stacks

Lastly, in terms of domains. I'm actually considering putting this feature into place, ideas are definitely appreciated on how this would be used / what would be ideal setup for you.

Currently, I would suggest creating the DNS manually once the stack is created :) this worked best for me in past (error mitigation as this part of infrastructure is not part of git). Alternatively, AWS-CLI is here to help (see: https://stackoverflow.com/questions/68493338/adding-domains-to-aws-cloudfront-distribution-via-api) or SDK/CDK.

My take at this point would probably be to create secondary CDK stack just for the domain, make it fetch Cloudfront distro ID from other stack and create A & AAAA records in your hosted zone.

judemanutd commented 1 year ago

Thanks, was contemplating forking the library as well and customizing it on my end. Looks like I'll need some brushing up on the CDK front.

On the domain front, things could get a bit complicated depending on how you want to go about it. I'm seeing 2 possible situations here

  1. The user already has the domain setup and is likely managing the resource outside of AWS
  2. The user has nothing setup and wants AWS to handle it

In case 1, I think it's simply a matter of accepting the domains as an environment variable and associating them with the Cloudfront distribution which I think can be done within the same stack.

In case 2, yeah I think creating a new stack would make managing it much simpler.

P.S. out of curiosity, are you looking to add additional configurations to this library at some point in the roadmap? Things like SSL certificate generation, customizing various attributes, etc. I only ask because this seems like quite an interesting avenue and I would love to contribute to this if you do plan on having that in the roadmap at some point.

sladg commented 1 year ago

FYI, I have added configuration for lambda's memory and timeout. Will look into DNS next.

judemanutd commented 1 year ago

Hey @sladg feel free to close this issue if you need to.

sladg commented 1 year ago

As of version 3.18.0 you can now pass additional parameters to deploy command and it will handle DNS, aliases and certificate creation :)

--hostedZone <domainName>    Hosted zone domain name to be used for creating DNS records (example: example.com).
--domainNamePrefix <prefix>  Prefix for creating DNS records, if left undefined, hostedZone will be used (example: app).