Skip to content

Commit

Permalink
docs(node): Add recipe for deploying AWS Lambda in Node.js (#16103)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndcunningham authored Apr 5, 2023
1 parent fa349ac commit ce308d3
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 1 deletion.
16 changes: 16 additions & 0 deletions docs/generated/manifests/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -2597,6 +2597,14 @@
"children": [],
"disableCollapsible": false
},
{
"name": "Deploying AWS lambda in Node.js",
"path": "/recipes/deployment/node-aws-lambda",
"id": "node-aws-lambda",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Serverless deployment with Deno Deploy",
"path": "/recipes/deployment/deno-deploy",
Expand Down Expand Up @@ -2632,6 +2640,14 @@
"children": [],
"disableCollapsible": false
},
{
"name": "Deploying AWS lambda in Node.js",
"path": "/recipes/deployment/node-aws-lambda",
"id": "node-aws-lambda",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Serverless deployment with Deno Deploy",
"path": "/recipes/deployment/deno-deploy",
Expand Down
20 changes: 20 additions & 0 deletions docs/generated/manifests/recipes.json
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,16 @@
"path": "/recipes/deployment/node-serverless-functions-netlify",
"tags": ["deployment", "node"]
},
{
"id": "node-aws-lambda",
"name": "Deploying AWS lambda in Node.js",
"description": "",
"file": "shared/recipes/deployment/node-aws-lambda",
"itemList": [],
"isExternal": false,
"path": "/recipes/deployment/node-aws-lambda",
"tags": ["deployment", "node"]
},
{
"id": "deno-deploy",
"name": "Serverless deployment with Deno Deploy",
Expand Down Expand Up @@ -1120,6 +1130,16 @@
"path": "/recipes/deployment/node-serverless-functions-netlify",
"tags": ["deployment", "node"]
},
"/recipes/deployment/node-aws-lambda": {
"id": "node-aws-lambda",
"name": "Deploying AWS lambda in Node.js",
"description": "",
"file": "shared/recipes/deployment/node-aws-lambda",
"itemList": [],
"isExternal": false,
"path": "/recipes/deployment/node-aws-lambda",
"tags": ["deployment", "node"]
},
"/recipes/deployment/deno-deploy": {
"id": "deno-deploy",
"name": "Serverless deployment with Deno Deploy",
Expand Down
14 changes: 14 additions & 0 deletions docs/generated/manifests/tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,13 @@
"name": "Deploying Node.js serverless functions to Netlify",
"path": "/recipes/deployment/node-serverless-functions-netlify"
},
{
"description": "",
"file": "shared/recipes/deployment/node-aws-lambda",
"id": "node-aws-lambda",
"name": "Deploying AWS lambda in Node.js",
"path": "/recipes/deployment/node-aws-lambda"
},
{
"description": "",
"file": "shared/recipes/deployment/deno-deploy",
Expand Down Expand Up @@ -872,6 +879,13 @@
"id": "node-serverless-functions-netlify",
"name": "Deploying Node.js serverless functions to Netlify",
"path": "/recipes/deployment/node-serverless-functions-netlify"
},
{
"description": "",
"file": "shared/recipes/deployment/node-aws-lambda",
"id": "node-aws-lambda",
"name": "Deploying AWS lambda in Node.js",
"path": "/recipes/deployment/node-aws-lambda"
}
],
"deno": [
Expand Down
6 changes: 6 additions & 0 deletions docs/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,12 @@
"tags": ["deployment", "node"],
"file": "shared/recipes/deployment/node-serverless-functions-netlify"
},
{
"name": "Deploying AWS lambda in Node.js",
"id": "node-aws-lambda",
"tags": ["deployment", "node"],
"file": "shared/recipes/deployment/node-aws-lambda"
},
{
"name": "Serverless deployment with Deno Deploy",
"id": "deno-deploy",
Expand Down
96 changes: 96 additions & 0 deletions docs/shared/recipes/deployment/node-aws-lambda.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Deploying AWS lambda functions in Node.js

Deploying AWS lambda functions in Node.js takes a few steps:

## Creating the project

For new workspaces you can create a Nx workspace with AWS lambda functions with one command:

```shell
npx create-nx-workspace@latest my-functions \
--preset=@nrwl/aws-lambda \
```

## Configuring existing projects

**Skip this step if you are not configuring an existing project.**

You will need to install `@nrwl/aws-lambda` if you haven't already.

{% tabs %}
{% tab label="npm" %}

```shell
npm i -D @nrwl/aws-lambda
```

{% /tab %}
{% tab label="yarn" %}

```shell
yarn add -D @nrwl/aws-lambda
```

{% /tab %}
{% tab label="pnpm" %}

```shell
pnpm add -D @nrwl/aws-lambda
```

{% /tab %}
{% /tabs %}

- Add AWS lambda configuration by running the following command:

```shell
nx generate @nrwl/aws-lambda:setup-serverless
```

- Create a new aws-lambda project with:

```shell
nx generate @nrwl/aws-lambda:serverless
```

This will do a few things:

1. Create a new AWS lambda function in directory `src/hello-world`.
2. Add `samconfig.toml` & `template.yaml` in the root of the project.
3. Update your `project.json` to have 2 new targets `serve` & `deploy`.

## Configure your AWS lambda deploy settings

{% callout type="note" title="Prerequiste" %}
You need to configure your AWS credentials inside AWS before attempting to deploy.

{% /callout %}

## Deployment

Before running your deployments you must have these:

- [SAM](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html#install-sam-cli-instructions) installed on your machine
- [Esbuild](https://esbuild.github.io/getting-started/) available in your PATH

```shell
npm install -g esbuild
```

To view your functions locally you run:

```shell
nx serve
```

Your `samconfig.toml` stores default parameters for SAM CLI.

If you want configure your lambda function settings such as the AWS region, runtime, and handler function. You can update your `template.yaml` file located at the root of your project.

To deploy them to AWS you would run:

```shell
nx deploy
```

That's it! Your AWS Lambda function should now be deployed using Nx. You can test it using the endpoint URL provided by Nx, and monitor its execution using the AWS Lambda console or other monitoring tools. Note that you may need to configure additional settings, such as event sources or permissions, depending on your specific use case.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ This will do a few things:

1. Create a new serverless function in `src/functions`.
2. Add the `netlify.toml` in the root of the project
3. Update your `project.json` to have 2 new targets `dev` & `deploy`.
3. Update your `project.json` to have 2 new targets `serve` & `deploy`.

## Configure your Netlify deploy settings

Expand Down

1 comment on commit ce308d3

@vercel
Copy link

@vercel vercel bot commented on ce308d3 Apr 5, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx.dev

Please sign in to comment.