-
Notifications
You must be signed in to change notification settings - Fork 1
Docs: Awos
- Introduction
- Installation
- Overview
-
Key Concepts
- AWS OpenSearch Integration
- CRUD Operations with Signed URL
- Rule-based Queries
-
Core Components
AwosModule
-
Key Factories
opensearchEntityCrudAdaptorPluginFactoryopensearchTemplateCrudAdaptorPluginFactorycreateSignedHttpRequest
-
Usage
- Registering the Plugin
- Performing CRUD Operations on OpenSearch
- Querying Data in OpenSearch
- API Reference
- Examples
- Testing
The Awos library provides seamless integration between Angular applications and AWS OpenSearch. It enables secure CRUD operations on OpenSearch entities and supports dynamic, rule-based queries using json-rules-engine. The library utilizes AWS Signature V4 for signed HTTP requests, ensuring secure interactions.
Install the library and necessary dependencies:
npm install awos @aws-sdk/client-opensearch @rollthecloudinc/crud @rollthecloudinc/auth @rollthecloudinc/awcog @rollthecloudinc/dparamAwos combines the power of AWS OpenSearch with Angular, enabling developers to perform secure operations like create, update, delete, and query on OpenSearch entities. Key features include:
- Integration with AWS Cognito for user authentication.
- Generation of signed URLs using AWS Signature V4 for secure requests.
- Rule-based and parameterized queries for flexible data retrieval from OpenSearch.
- CRUD Operations: Supports CRUD operations on OpenSearch documents and templates.
-
Rule-based Queries: Enables complex filtering using
json-rules-engine. - Secure Signed URLs: Leverages AWS Signature V4 for authenticated requests to OpenSearch.
- Dependency Injection: Provides reusable factories and services for OpenSearch integration.
The library generates signed HTTP requests to interact securely with AWS OpenSearch endpoints. It supports both entity-based operations and template queries.
CRUD operations (create, update, delete, query) are securely executed using AWS signed requests. These ensure that interactions with OpenSearch are authenticated and authorized.
Leverage json-rules-engine to perform filtering or conditional fetching of OpenSearch documents. Dynamic rules can be applied to structure flexible template queries.
The AwosModule is the primary module for library integration. It registers plugins that enable CRUD operations using OpenSearch templates or entities. Dependencies such as AuthFacade and ParamEvaluatorService ensure smooth authentication and parameter resolution.
Example Usage:
import { AwosModule } from 'awos';
@NgModule({
imports: [AwosModule],
declarations: [],
bootstrap: [AppComponent],
})
export class AppModule {}Creates an adaptor plugin capable of handling CRUD operations on OpenSearch entities. All operations (create, update, delete, query) rely on AWS signed requests for security.
Features:
- Entity-based operations: Direct interaction with OpenSearch documents.
- Parameterized options: Allows flexible configurations like domain, region, pipeline, and index.
- Query execution: Supports retrieval of documents using rule-based logic.
Creates an adaptor plugin for executing OpenSearch template-based queries with custom parameters and rules.
Features:
- Template-based queries: Fetch results using OpenSearch templates.
- Rule evaluations: Dynamic query conditions can be applied via
json-rules-engine. - Secure execution: All operations are authenticated using signed HTTP requests.
This utility generates signed HTTP requests for interactions with OpenSearch by leveraging AWS Signature V4. The signed URL ensures that only authenticated and authorized clients can make requests.
Parameters:
-
body: Request payload. -
headers: Custom headers for the request. -
hostname: OpenSearch domain hostname. -
method: HTTP method. -
path: REST API path to target OpenSearch resources. -
protocol: Request protocol (http,https). -
service: AWS service identifier (esfor OpenSearch). -
authFacade: Used for authentication via Cognito tokens. -
cognitoSettings: AWS Cognito settings.
To use the OpenSearch plugins (aws_opensearch_entity, aws_opensearch_template), import the AwosModule and configure AWS Cognito settings.
Example:
import { AwosModule } from 'awos';
import { CognitoSettings, COGNITO_SETTINGS } from '@rollthecloudinc/awcog';
const cognitoSettings: CognitoSettings = {
identityPoolId: 'us-east-1:xxxxxx',
region: 'us-east-1',
userPoolId: 'us-east-1_xxxxxx',
};
@NgModule({
imports: [AwosModule],
providers: [{ provide: COGNITO_SETTINGS, useValue: cognitoSettings }],
})
export class AppModule {}Write a document to OpenSearch securely using the create method.
Example:
const crudInput = {
object: { id: '123', name: 'New Document' },
params: { domain: 'opensearch-domain', region: 'us-east-1', index: 'myIndex' },
identity: () => of({ identity: 'document123' }),
};
opensearchEntityCrudAdaptorPluginFactory(authFacade, cognitoSettings, paramEvaluatorService, httpClient)
.create(crudInput)
.subscribe((response) => console.log('Create successful:', response.success));Modify an existing OpenSearch document using the update method.
Example:
const crudInput = {
object: { id: '123', name: 'Updated Document' },
params: { domain: 'opensearch-domain', region: 'us-east-1', index: 'myIndex' },
identity: () => of({ identity: 'document123' }),
};
opensearchEntityCrudAdaptorPluginFactory(authFacade, cognitoSettings, paramEvaluatorService, httpClient)
.update(crudInput)
.subscribe((response) => console.log('Update successful:', response.success));Retrieve OpenSearch documents using rule-based filtering.
Example:
const queryInput = {
params: { domain: 'opensearch-domain', region: 'us-east-1', index: 'myIndex' },
rule: {
conditions: {
all: [
{ fact: 'identity', operator: 'startsWith', value: 'doc' },
],
},
event: { type: 'visible' },
},
};
opensearchEntityCrudAdaptorPluginFactory(authFacade, cognitoSettings, paramEvaluatorService, httpClient)
.query(queryInput)
.subscribe((response) => console.log('Queried entities:', response.entities));Fetch data using OpenSearch templates.
Example:
const templateQueryInput = {
params: { domain: 'opensearch-domain', region: 'us-east-1', index: 'my-template-index' },
rule: {
event: { type: 'visible' },
conditions: { all: [{ fact: 'searchTerm', operator: 'term', value: 'example' }] },
},
};
opensearchTemplateCrudAdaptorPluginFactory(platformId, authFacade, cognitoSettings, paramEvaluatorService, httpClient)
.query(templateQueryInput)
.subscribe((response) => console.log('Template query result:', response.entities));-
opensearchEntityCrudAdaptorPluginFactorycreate(input: CrudOperationInput): Observable<CrudOperationResponse>update(input: CrudOperationInput): Observable<CrudOperationResponse>query(input: CrudCollectionOperationInput): Observable<CrudCollectionOperationResponse>
-
opensearchTemplateCrudAdaptorPluginFactoryquery(input: CrudCollectionOperationInput): Observable<CrudCollectionOperationResponse>
-
createSignedHttpRequest(params: CreateSignHttpRequestParams): Observable<HttpRequest>- Generates AWS Signature V4 signed HTTP requests.
const input = {
params: { domain: 'search-domain', region: 'us-west-2', index: 'products' },
rule: {
conditions: {
all: [
{ fact: 'identity', operator: 'startsWith', value: 'prod' },
],
},
event: { type: 'visible' },
},
};
opensearchEntityCrudAdaptorPluginFactory(...dependencies)
.query(input)
.subscribe((response) => console.log('Queried results:', response.entities));describe('opensearchEntityCrudAdaptorPluginFactory', () => {
it('should query OpenSearch entities based on rules', () => {
const input = {
params: { domain: 'test-domain', region: 'us-east-1', index: 'test-index' },
rule: {
conditions: { all: [{ fact: 'identity', operator: 'startsWith', value: 'test' }] },
event: { type: 'visible' },
},
};
opensearchEntityCrudAdaptorPluginFactory(...dependencies)
.query(input)
.subscribe((response) => expect(response.entities.length).toBeGreaterThan(0));
});
});The Awos Angular library enables secure interaction with AWS OpenSearch using authenticated signed URLs. It provides robust support for CRUD operations, parameterized template queries, and rule-based filtering. Whether you're managing documents or performing advanced searches, Awos delivers reliable tools for modern SaaS applications.
For questions, feature requests, or contributions, reach out!