Movatterモバイル変換


[0]ホーム

URL:


Skip to content
NxNxDocs
ContactTry Nx Cloud for free
GitHubYouTubeXDiscord

The @nx/aws-lambda plugin is deprecated and unmaintained. We are committed to providing high-quality tooling to community, and we no longer have the capacity to keep this plugin updated.

This recipe guides you through setting up AWS Lambda functions with Nx.

Depending on your current situation, you can either

  • create a new project with the goal of primarily developing and publishing AWS Lambda functions
  • add AWS Lambda functions to an existing Node.js project in an Nx workspace

To create a new project, run

npxcreate-nx-workspace@latestmy-functions--preset=@nx/aws-lambda

First, make sure you have@nx/aws-lambda installed.

nxadd@nx/aws-lambda

Next, use the corresponding Nx generator to add the AWS Lambda configuration to an existing project:

nxgenerate@nx/aws-lambda:setup-functions

This will setup your project to use AWS Lambda functions:

  1. Creates a new AWS lambda function in directoryfunctions/hello-world.
  2. Addssamconfig.toml andtemplate.yaml in the root of the project.
  3. Updates yourproject.json to have 2 new targetsserve-functions &deploy-functions.

Theproject.json should have a new targetserve-functions:

project.json
{
"name":"my-functions",
...
"targets": {
...
"serve-functions": {
"command":"sam build && sam local start-api"
},
...
}
}

This allows to just runnx serve-functions to start a local server that serves your functions. As you can see it leverages theSAM CLI underneath.

You need to configure your AWS credentials inside AWS before attempting to deploy.

The following requirements need to be met in order to run the AWS Lambda function deployment:

  • SAM installed on your machine
  • esbuild available in your PATH (SAM need this). Example:npm install -g esbuild.

Yoursamconfig.toml stores default parameters for the SAM CLI. On the other hand, if you want to configure your lambda function settings such as the AWS region, runtime, and handler function, update yourtemplate.yaml.

The Nxproject.json already contains adeploy-functions target we can invoke to trigger the deployment:

project.json
{
"name":"my-functions",
...
"targets": {
...
"deploy-functions": {
"command":"sam build && sam deploy --guided"
}
}
}

Just run:

nxdeploy-functions

That's it! For monitoring or further permission settings, please refer to the AWS Lambda console.


[8]ページ先頭

©2009-2025 Movatter.jp