diff --git a/README.md b/README.md index ffb1086..d8f01a3 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,38 @@ const client = await search() Now `client` is an instance of the [OpenSearch JavaScript client](https://opensearch.org/docs/latest/clients/javascript/index/), and you can call any client method on it — for example, [`client.index.create()`](https://opensearch.org/docs/latest/clients/javascript/index/#creating-an-index), [`client.index()`](https://opensearch.org/docs/latest/clients/javascript/index/#indexing-a-document), or [`client.search()`](https://opensearch.org/docs/latest/clients/javascript/index/#searching-for-documents). +## Making post-deployment requests to OpenSearch or ElasticSearch from your application + +If you would like to make requests to automatically configure your OpenSearch or ElasticSearch instance after deployment, you may optionally add a postdeploy-search.js file in the root directory of your Architect project. This file should export a function that takes no arguments as its default export. Be sure to connect with your OpenSearch or ElasticSearch instance before making your requests. + +Here's an sample postdeploy-search.js file for making requests to OpenSearch: + +```ts +import { search } from '@nasa-gcn/architect-functions-search' + +export default async function () { + const client = await search() + + //Set cluster settings + const cluster_settings_request = { + method: 'PUT', + path: '/_cluster/settings', + body: { + persistent: { + cluster.max_shards_per_node: '500', + }, + }, + } + + try { + await client.transport.request(cluster_settings_request) + } catch (e) { + console.log('Error: ', e) + return + } +} +``` + ## Advanced usage from your application If you would like to manually connect to OpenSearch from your application, then you will need to sign your requests using [AWS SIG4](https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html); the OpenSearch client library provides the [`AwsSigv4Signer`](https://opensearch.org/docs/latest/clients/javascript/index/#authenticating-with-amazon-opensearch-service--aws-sigv4) helper to automate this.