Skip to content

Commit

Permalink
Support both OpenSearch Service and OpenSearch Serverless
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsinger committed Mar 9, 2023
1 parent 26a83ac commit bbe6392
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

This package provides an automatically configured [client for OpenSearch](https://opensearch.org/docs/latest/clients/javascript/index/) in an [Architect](https://arc.codes/) application.

Pair this package with [@nasa-gcn/architect-plugins-search](https://github.com/nasa-gcn/architect-plugins-search), a [plugin](https://arc.codes/docs/en/guides/plugins/overview) that adds [Amazon OpenSearch Serverless](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless.html) to your application.
Pair this package with [@nasa-gcn/architect-plugins-search](https://github.com/nasa-gcn/architect-plugins-search), a [plugin](https://arc.codes/docs/en/guides/plugins/overview) that adds [Amazon OpenSearch](https://aws.amazon.com/opensearch-service/) to your application.
9 changes: 5 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import memoizee from 'memoizee'
export const search = memoizee(
async () => {
const discoveredServices = await services()
const node =
discoveredServices['nasa-gcn']?.['architect-plugin-search']?.node
const props = discoveredServices['nasa-gcn']?.['architect-plugin-search']
const node = props?.node
const service = props?.sig4service
if (!node) throw new Error('unknown endpoint')

const options = { node }

if (new URL(node).hostname !== 'localhost') {
if (service) {
const region = process.env.AWS_REGION
if (!region)
throw new Error('environment variable AWS_REGION must be defined')
Expand All @@ -30,7 +31,7 @@ export const search = memoizee(
region,
// @ts-expect-error: service is missing from type definition;
// fixed in https://github.com/opensearch-project/opensearch-js/pull/377
service: 'aoss',
service,
})
)
}
Expand Down

0 comments on commit bbe6392

Please sign in to comment.