<commit_before># Customising deployments

Claudia has lots of options to customise deployments. You can configure the function name, reserved memory, timeouts and a lot more by providing additional options to the `claudia create` command. To get a full list of supported options, check out the [Claudia Create Docs](https://github.com/claudiajs/claudia/blob/master/docs/create.md) or run:

```bash
claudia create --help
```

## Selecting and excluding files from your package

Claudia tries very hard to stay out of your way and let you define the projects the way you want to. If you do not want to use automatically generated API Gateway definitions, there are no special constraints or dependencies that you need to think about -- just follow the regular NPM packaging practices.

Claudia expects the standard NPM `package.json` file. You can use standard NPM packaging techniques to include or exclude files to your deployment.

  * all the standard patterns ignored by NPM are ignored by Claudia as well (including `.git`, `.hg` and so on)
  * if `.gitignore` or `.npmignore` exist, patterns listed in those files will be excluded
  * if the `package.json` file includes the `files` property, only those patterns will be included. See the [files section of the NPM configuration guide](https://docs.npmjs.com/files/package.json#files) for more information.
  
It's a good practice, although not necessary, to explicitly list the files or file patterns you want to deploy in the `files` property of `package.json`. This will ensure you avoid deploying test and development resources and local configuration files. You do not have to list `package.json` here, it will automatically be included.  

Although the AWS Node.js deployment guide requires including the `node_modules` folder for deployment, don't add it to the `files` section. Claudia will do that automatically for you. Even better, while preparing a package, Claudia will copy all the relevant files to a temporary project and install production dependencies only, so you are sure to deploy only the relevant module files. 

If you need to do any post-processing or validation before deployment, you can do that in the NPM `post-install` lifecycle task. Because Claudia runs `npm install` to fetch the dependencies, the post-install task will kick-off directly after the dependencies are downloaded, and before the package is uploaded to AWS.

## Working with API Gateway web APIs

Claudia can create an API Gateway definition, wire up integration templates and even simplify routing so that a single Lambda function can handle multiple web API URLs. For that, create a WEB API module using the [Claudia API Builder](https://github.com/claudiajs/claudia-api-builder) and supply the routing module name instead of a handler to create the project:

```bash
claudia create --name LAMBDA_NAME --region AWS_REGION --api-module ROUTING_MODULE
```

See the [Web Api Example Project](https://github.com/claudiajs/example-projects/tree/master/web-api) for a trivial example of how to wire up a single lambda to multiple HTTP paths.

## Using different versions for development, testing and production

Each time a Lambda function is deployed, it gets assigned a sequential deployment number. Event sources can be configured to publish events to a particular Lambda deployment number, or an alias (named pointer to a numeric version). This makes it easy to use a single Lambda function for development, production and testing environments. You can create a named alias by supplying `--version` to `claudia create` or `claudia update` and Claudia will automatically associate a named alias with the current deployment number. For example:

```bash
claudia update --version testing
```

You can also re-assign a named alias to the last deployed version quickly. This is useful, for example, after you have finished testing and want to promote the current deployment to production. Use: 

```bash
claudia set-version --version ALIAS_NAME
```

Claudia will automatically create a new alias for the currently deployed version, or re-assign an existing alias to it. The big difference between `set-version` and `update` is that `update` causes a new deployment from your local file system, and `set-version` uses the last deployed version. 

If your project includes an API Gateway definition, this will also create a new deployment of the web API, and create or re-assign an API Gateway stage, linking it directly to the Lambda alias. 

## Working with pre-existing lambda/API gateway resources<commit_msg>info on using local deps<commit_after># Customising deployments

Claudia has lots of options to customise deployments. You can configure the function name, reserved memory, timeouts and a lot more by providing additional options to the `claudia create` command. To get a full list of supported options, check out the [Claudia Create Docs](https://github.com/claudiajs/claudia/blob/master/docs/create.md) or run:

```bash
claudia create --help
```

## Selecting and excluding files from your package

Claudia tries very hard to stay out of your way and let you define the projects the way you want to. If you do not want to use automatically generated API Gateway definitions, there are no special constraints or dependencies that you need to think about -- just follow the regular NPM packaging practices.

Claudia expects the standard NPM `package.json` file. You can use standard NPM packaging techniques to include or exclude files to your deployment.

  * all the standard patterns ignored by NPM are ignored by Claudia as well (including `.git`, `.hg` and so on)
  * if `.gitignore` or `.npmignore` exist, patterns listed in those files will be excluded
  * if the `package.json` file includes the `files` property, only those patterns will be included. See the [files section of the NPM configuration guide](https://docs.npmjs.com/files/package.json#files) for more information.
  
It's a good practice, although not necessary, to explicitly list the files or file patterns you want to deploy in the `files` property of `package.json`. This will ensure you avoid deploying test and development resources and local configuration files. You do not have to list `package.json` here, it will automatically be included.  

Although the AWS Node.js deployment guide requires including the `node_modules` folder for deployment, don't add it to the `files` section. Claudia will do that automatically for you. Even better, while preparing a package, Claudia will copy all the relevant files to a temporary project and install production dependencies only, so you are sure to deploy only the relevant module files. 

If you need to do any post-processing or validation before deployment, you can do that in the NPM `post-install` lifecycle task. Because Claudia runs `npm install` to fetch the dependencies, the post-install task will kick-off directly after the dependencies are downloaded, and before the package is uploaded to AWS.

### Using local NPM modules

By default, Claudia will not copy the local `node_modules`, but instead do a clean production installation in a temporary directory. This is to avoid copying testing and development dependencies, and also to validate as much as possible locally before sending the code to AWS. If you would like to skip that step, and use the local `node_modules`, supply `--use-local-dependencies` with your `create` or `update` command. 

This might be useful if you want to send up precompiled binaries for a different platform (eg you use Windows locally, but want to send compiled Linux binaries), or if you use local relative paths in your `package.json`.

## Working with API Gateway web APIs

Claudia can create an API Gateway definition, wire up integration templates and even simplify routing so that a single Lambda function can handle multiple web API URLs. For that, create a WEB API module using the [Claudia API Builder](https://github.com/claudiajs/claudia-api-builder) and supply the routing module name instead of a handler to create the project:

```bash
claudia create --name LAMBDA_NAME --region AWS_REGION --api-module ROUTING_MODULE
```

See the [Web Api Example Project](https://github.com/claudiajs/example-projects/tree/master/web-api) for a trivial example of how to wire up a single lambda to multiple HTTP paths.

## Using different versions for development, testing and production

Each time a Lambda function is deployed, it gets assigned a sequential deployment number. Event sources can be configured to publish events to a particular Lambda deployment number, or an alias (named pointer to a numeric version). This makes it easy to use a single Lambda function for development, production and testing environments. You can create a named alias by supplying `--version` to `claudia create` or `claudia update` and Claudia will automatically associate a named alias with the current deployment number. For example:

```bash
claudia update --version testing
```

You can also re-assign a named alias to the last deployed version quickly. This is useful, for example, after you have finished testing and want to promote the current deployment to production. Use: 

```bash
claudia set-version --version ALIAS_NAME
```

Claudia will automatically create a new alias for the currently deployed version, or re-assign an existing alias to it. The big difference between `set-version` and `update` is that `update` causes a new deployment from your local file system, and `set-version` uses the last deployed version. 

If your project includes an API Gateway definition, this will also create a new deployment of the web API, and create or re-assign an API Gateway stage, linking it directly to the Lambda alias. 

## Working with pre-existing lambda/API gateway resources
{'fraction_non_alphanumeric': 0.052959183673469384, 'fraction_numerical': 0.0, 'mean_word_length': 4.626291618828932, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2102371', 'n_tokens_mistral': 2371, 'n_tokens_neox': 2280, 'n_words': 1436}