Skip to content

Commit

Permalink
Improving documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
tarehart committed Dec 11, 2023
1 parent f88af6d commit a3dc079
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,26 @@

A wrapper around @aws-sdk/client-appconfigdata to provide background polling and caching.

Although AWS seems to recommend their [simplified retrieval methods](https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-retrieving-simplified-methods.html) for fetching AppConfig, i.e. running an agent in a separate process, you may prefer to use this library:

- You don't need to set up a lambda extension.
- You easily get parity between your local development server and prod.
- The parsed version of your config is conveniently cached.
- You get convenient reporting of transient errors while the library works in the background to recover.

## Usage

Initialize:

```typescript
import { AppConfigDataClient } from '@aws-sdk/client-appconfigdata';
import { Poller } from 'aws-appconfig-poller';

const dataClient = new AppConfigDataClient({
// Set up credentials, region, etc, as necessary.
credentials: undefined,
});

const poller = new Poller({
dataClient: dataClient,
sessionConfig: {
Expand Down Expand Up @@ -36,6 +51,8 @@ Fetch:
const { latestValue } = poller.getConfigurationObject();
```

For full working code, see examples/infinitePoller.ts.

## Error handling

A few things can go wrong when polling for AppConfig, such as:
Expand Down
2 changes: 2 additions & 0 deletions examples/infinitePoller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ if (!isInitiallySuccessful) {

console.log('Connection succeeded at:', new Date());

// Normally you would not use setInterval in your app, this is just to help us
// periodically log the state of the configuration object to prove it's working.
setInterval(() => {
const obj = poller.getConfigurationObject();
console.log('Current config entry', obj);
Expand Down

0 comments on commit a3dc079

Please sign in to comment.