-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(node): Add recipe for deploying AWS Lambda in Node.js (#16103)
- Loading branch information
1 parent
fa349ac
commit ce308d3
Showing
6 changed files
with
153 additions
and
1 deletion.
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
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
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
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
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,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. |
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
ce308d3
There was a problem hiding this comment.
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