Skip to content

Add Next.js Zip example#66

Merged
bnusunny merged 4 commits intoaws:mainfrom
julianbonilla:nextjs-example
Sep 7, 2022
Merged

Add Next.js Zip example#66
bnusunny merged 4 commits intoaws:mainfrom
julianbonilla:nextjs-example

Conversation

@julianbonilla
Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:

Add an example for Next.js 12 using Zip package type.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Comment thread examples/nextjs-zip/app/run.sh Outdated
@@ -0,0 +1,3 @@
#!/bin/bash

node server.js No newline at end of file
Copy link
Copy Markdown
Contributor

@bnusunny bnusunny Sep 2, 2022

Choose a reason for hiding this comment

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

Two updates for this line:

  1. server.js is under standalone directory.
  2. Adding exec to allow the nodejs process to receive SIGTERM for graceful shutdown.

exec node standalone/server.js

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

server.js is at the root of the artifacts directory, so I updated to exec node server.js

$ pwd
aws-lambda-web-adapter/examples/nextjs-zip/.aws-sam/build/NextjsFunction
$ tree -I node_modules/
.
├── .next
├── node_modules
├── package.json
├── public
│   ├── favicon.ico
│   └── vercel.svg
├── run.sh
└── server.js

Copy link
Copy Markdown
Contributor

@bnusunny bnusunny Sep 2, 2022

Choose a reason for hiding this comment

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

I built this example. The server.js was under standalone folder. If this is not intended, the build command in the Makefile should be checked.

[ec2-user@ip-172-31-42-124 nextjs-zip]$ ls -l .aws-sam/build/NextjsFunction/
total 4
-rw-rw-r-- 1 ec2-user ec2-user 44 Sep 2 15:28 run.sh
drwxrwxr-x 5 ec2-user ec2-user 90 Sep 2 15:28 standalone

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I can't reproduce. You're running sam build from nextjs-zip directory?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes. I run sam build from nextjs-zip directory on an ec2 instance. The OS is Amazon Linux 2. The shell is bash.

receive SIGTERM for graceful shutdown
Comment thread examples/nextjs-zip/app/Makefile Outdated
cp -r .next/static/ .next/standalone/.next/static

# Copy artifacts for deployment
cp -r .next/standalone/ $(ARTIFACTS_DIR)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Change this line to this: cp -r .next/standalone/. $(ARTIFACTS_DIR)

This works on both LInux and Macos.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please also look at other copy commands in the Makefile.

Copy link
Copy Markdown
Contributor

@bnusunny bnusunny left a comment

Choose a reason for hiding this comment

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

LGTM

@bnusunny
Copy link
Copy Markdown
Contributor

bnusunny commented Sep 7, 2022

@julianbonilla This is a great example. Thanks for the contribution!

@bnusunny bnusunny merged commit 608e0d9 into aws:main Sep 7, 2022
@julianbonilla julianbonilla deleted the nextjs-example branch September 7, 2022 18:37
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.

2 participants