npm package: @nodesource/nsolid-serverless
Description: Tool to build infraestructure for serverless monitor in N|Solid
Author: Node Source
Latest version: 1.0.3

# @nodesource/nsolid-serverless

## Description

`@nodesource/nsolid-serverless` is a Node.js module that provides a Command Line Interface (CLI) for setting up infrastructure related to NodeSource N|Solid in a serverless environment. The main aim of this CLI tool is to enable users to instrument their serverless functions with N|Solid, a powerful Node.js application monitoring platform.

By utilizing `@nodesource/nsolid-serverless`, users can easily manage various resources such as infrastructures and functions, and perform cleanup operations on them. This tool streamlines the process of configuring the necessary infrastructure so that developers can seamlessly monitor and gain valuable insights into the performance of their serverless functions using N|Solid.

**Please Note**: At the moment, `@nodesource/nsolid-serverless` only supports AWS as the serverless environment. However, we have exciting plans on our roadmap to add support for Google Cloud Functions and Azure Functions in the future. Stay tuned for updates!

## Prerequisites

Before using `@nodesource/nsolid-serverless`, ensure that you have set up the necessary credentials for your cloud provider. Currently, only AWS is supported as the serverless environment. To set up AWS credentials, you can use the [AWS Command Line Interface (CLI)](https://aws.amazon.com/cli/) and run the following command:

```bash
aws configure
```

Follow the prompts to enter your AWS Access Key ID, Secret Access Key, default region, and output format.

## Installation

To use `@nodesource/nsolid-serverless`, you need to have Node.js and npm (Node Package Manager) installed on your system. If you don't have them, you can download and install them from [here](https://nodejs.org/).

Once you have Node.js and npm set up, you can install `@nodesource/nsolid-serverless` globally using the following command:

```bash
npm install -g @nodesource/nsolid-serverless
```

Alternatively, you can use npx to run @nodesource/nsolid-serverless without installing it globally:

```bash
npx @nodesource/nsolid-serverless <resource> [command] [options]
```

## Usage

The CLI follows the following format:

```bash
nsolid-serverless <resource> [command] [options]
```

### `<resource>`

The `<resource>` can be one of the following:
- `infra`: For managing infrastructure.
- `functions`: For managing functions.
- `removeAll`: For removing all resources.

### `[command]`

The `[command]` applies to `infra` and `functions` resources. It can have the following values:

- `--install`: Install the specified resource.
- `--update`: Update the specified resource.
- `--uninstall`: Uninstall the specified resource.

### Common Options (Applicable to `infra`, `functions`, and `removeAll`)

- `--region`: Specify the region where the resource will be created in your cloud environment. For example, `--region us-west-2`.

- `--stage`: Specify the stage of the created resource. For example, `--stage dev` or `--stage prod`.

### Options specific to `functions`

- `--functionPatterns`: Filter the functions that will be monitored using a regular expression or a function name pattern. For example, `--functionPatterns "myFunctionName|myFunctionName2|myFunctionName3"`.

- `--tracing`: Enable collecting traces from the function invocations. This option is applicable only to `functions`.

### Examples

#### Non-interactive mode

- Create a new infrastructure in the `eu-west-3` region and stage `dev`:
  ```bash
  nsolid-serverless infra --install --region eu-west-3 --stage dev
  ```

- Deploy a new function and enable metrics collection in the `us-east-1` region and stage `prod`:
  ```bash
  nsolid-serverless functions --install --region us-east-1 --stage prod --functionPatterns "myFunctionName|myFunctionName2"
  ```

- Uninstall the infrastructure in the `us-west-2` region and stage `dev`:
  ```bash
  nsolid-serverless infra --uninstall --region us-west-2 --stage dev
  ```

#### Interactive mode

Interactive mode is available when at least one of the required options (`--region`, `--stage`, `--functionPatterns`) is not used.

- Install a new infrastructure:
  ```bash
  nsolid-serverless infra --install
  ```
  Interactive mode prompts:
  ```
  In which region do you want to deploy?
  In which stage do you want to deploy?
  ```

- Install a new function and enable metrics collection:
  ```bash
  nsolid-serverless functions --install
  ```
  Interactive mode prompts:
  ```
  In which region do you want to deploy?
  In which stage do you want to deploy?
  Which functions do you want to collect metrics?
  ```

- Uninstall a function:
  ```bash
  nsolid-serverless functions --uninstall
  ```
  Interactive mode prompts:
  ```
  In which region do you want to uninstall?
  In which stage do you want to uninstall?
  Which function do you want to uninstall?
  ```

- Remove all resources:
  ```bash
  nsolid-serverless removeAll
  ```

## Contribution

Contributions to `@nodesource/nsolid-serverless` are welcome. If you find any issues or have suggestions for improvement, please feel free to open an issue or submit a pull request on the [GitHub repository](https://github.com/nodesource/nsolid-serverless).

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.