|
| 1 | +# HOWTO: Use `elastic-package` to test packages using a Serverless project |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +`elastic-package` supports creating a new Serverless project to assist developers in testing their own packages in these offerings. |
| 6 | + |
| 7 | +**Please note:** Testing packages using this method may result in additional charges. |
| 8 | + |
| 9 | + |
| 10 | +### The `serverless` stack provider |
| 11 | + |
| 12 | +The `serverless` provider facilitates the creation and management of a Serverless project, running the Elastic Agent and other services as local containers using Docker compose. |
| 13 | + |
| 14 | +To use the `serverless` provider, follow these steps: |
| 15 | +1. Obtain an API key from [Elastic Cloud API keys](https://cloud.elastic.co/account/keys). |
| 16 | +2. Set the environment variable `EC_API_KEY` with the obtained API key: |
| 17 | + ```shell |
| 18 | + export EC_API_KEY=<api_key> |
| 19 | + ``` |
| 20 | +3. (Recommended) Create a new elastic-package profile for serverless: |
| 21 | + ```shell |
| 22 | + elastic-package profiles create serverless |
| 23 | + elastic-package profiles use serverless |
| 24 | + ``` |
| 25 | +4. Update the profile configuration with the following keys (e.g. `~/.elastic-package/profiles/serverless/config.yml`): |
| 26 | + ```yaml |
| 27 | + stack.elastic_cloud.host: https://cloud.elastic.co |
| 28 | + # supported observability and security types |
| 29 | + stack.serverless.type: observability |
| 30 | + stack.serverless.region: aws-us-east-1 |
| 31 | + ``` |
| 32 | +
|
| 33 | +After completing these steps, create a new Elastic Serverless project by running: |
| 34 | +```sh |
| 35 | +elastic-package stack up -v -d --provider serverless |
| 36 | +``` |
| 37 | + |
| 38 | +Once this command finishes successfully, your environment will be ready to use |
| 39 | +any `elastic-package` subcommand (`install`, `dump`, `test`, ...) targeting the Serverless project created with the above command. |
| 40 | + |
| 41 | +To clean up everything, run: |
| 42 | +```sh |
| 43 | +elastic-package stack down -v |
| 44 | +``` |
| 45 | + |
| 46 | +**Recommendation:** Ensure that Serverless projects are properly deleted upon completion of testing to avoid any unexpected charges. |
| 47 | + |
| 48 | +Although Serverless projects are accessible through the management UI at [Elastic Cloud Projects](https://cloud.elastic.co/projects), |
| 49 | +those projects created by `elastic-package` must be deleted using the `stack down` command as previously mentioned. |
| 50 | +This procedure ensures that all resources and local configurations are cleaned up correctly, thereby allowing `elastic-package` to function |
| 51 | +correctly in subsequent commands. |
| 52 | + |
| 53 | +If you need to switch back to a local stack, remember to change to the previous profile. If the previous profile was `default`, run: |
| 54 | +```shell |
| 55 | +elastic-package profiles use default |
| 56 | +``` |
| 57 | + |
| 58 | +### Considerations about testing with the `serverless` provider |
| 59 | + |
| 60 | +There are some known issues when running pipeline tests with the `serverless` provider. |
| 61 | + |
| 62 | +In Serverless projects, the GeoIP database cannot be modified as it is done with local stack. |
| 63 | +To avoid errors related to those GeoIP fields in these tests, the results from |
| 64 | +pipeline tests should not be compared. This can be achieved by setting the following environment variable: |
| 65 | +```shell |
| 66 | +export ELASTIC_PACKAGE_SERVERLESS_PIPELINE_TEST_DISABLE_COMPARE_RESULTS=true |
| 67 | +``` |
| 68 | + |
| 69 | +### How to use an existing `Serverless` project |
| 70 | + |
| 71 | +In case you want to test your packages using an already existing Serverless project, it could be used |
| 72 | +the `environment` provider instead. |
| 73 | +You can learn more about this in [this document](https://github.com/elastic/elastic-package/blob/main/docs/howto/use_existing_stack.md). |
| 74 | + |
| 75 | +**IMPORTANT**: This provider modifies the Fleet configuration of the target stack. |
| 76 | +Avoid using it in environments that you use for other purposes, specially in production environments |
0 commit comments