-
-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add example for custom lambda handler
- Loading branch information
1 parent
77b206d
commit e16a153
Showing
6 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
## app-with-custom-lambda-handler | ||
|
||
### Running the example | ||
|
||
```shell | ||
git clone https://github.com/danielcondemarin/serverless-nextjs-plugin | ||
cd serverless-nextjs-plugin/examples/app-with-custom-lambda-handler | ||
``` | ||
|
||
#### Install dependencies | ||
|
||
```shell | ||
npm install | ||
``` | ||
|
||
_next.config.js_ | ||
|
||
```js | ||
module.exports = { | ||
... | ||
target: "serverless" | ||
}; | ||
``` | ||
|
||
#### Deploy | ||
|
||
`serverless deploy` | ||
|
||
After deployment is finished, visit the `/home` page, go to CloudWatch and check the LogGroup for the HomePage lambda to see the extra logging added by `my-lambda-handler.js` |
14 changes: 14 additions & 0 deletions
14
examples/app-with-custom-lambda-handler/my-lambda-handler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const compat = require("serverless-nextjs-plugin/aws-lambda-compat"); | ||
|
||
module.exports = page => { | ||
const handler = (event, context, callback) => { | ||
// let's add some logging | ||
console.log("URL: ", event.path); | ||
|
||
// render page | ||
compat(page)(event, context, callback); | ||
|
||
console.log("This is cool (☞゚∀゚)☞"); | ||
}; | ||
return handler; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
target: "serverless" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "app-with-custom-lambda-handler", | ||
"version": "1.0.0", | ||
"description": "Example nextjs serverless app using a custom lambda handler", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/danielcondemarin/serverless-nextjs-plugin.git" | ||
}, | ||
"keywords": [ | ||
"serverless", | ||
"nextjs", | ||
"lambda" | ||
], | ||
"author": "Daniel Conde Marin <[email protected]>", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/danielcondemarin/serverless-nextjs-plugin/issues" | ||
}, | ||
"homepage": "https://github.com/danielcondemarin/serverless-nextjs-plugin#readme", | ||
"dependencies": { | ||
"next": "^8.0.3", | ||
"react": "^16.8.4", | ||
"react-dom": "^16.8.4" | ||
}, | ||
"devDependencies": { | ||
"eslint-plugin-react": "^7.12.4", | ||
"serverless": "^1.39.1", | ||
"serverless-nextjs-plugin": "^1.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from "react"; | ||
|
||
function Index() { | ||
return <div>Welcome to next.js serverless ⚡</div>; | ||
} | ||
|
||
export default Index; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
service: app-with-custom-handler | ||
|
||
provider: | ||
name: aws | ||
runtime: nodejs8.10 | ||
memorySize: 512 | ||
|
||
stage: dev | ||
region: eu-west-1 | ||
|
||
plugins: | ||
- serverless-nextjs | ||
|
||
custom: | ||
serverless-nextjs: | ||
nextConfigDir: ./ | ||
customHandler: ./my-lambda-handler.js | ||
|
||
package: | ||
# exclude everything | ||
# page handlers are automatically included by the plugin | ||
exclude: | ||
- ./** |