> For the complete documentation index, see [llms.txt](https://shiftcode.gitbook.io/dynamo-easy/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://shiftcode.gitbook.io/dynamo-easy/api/dynamo-easy-config/configuration.md).

# Dynamo-Easy Config

{% embed url="<https://shiftcode.github.io/dynamo-easy/modules/dynamo_easy.html>" %}
technical api doc
{% endembed %}

## Authorization

The AWS SDK creates a Snapshot of the credentials when creating the underlying DynamoDB client, if you use short-lived credentials (for instance with Cognito Identity) you have to ensure the credentials are valid before making requests.

{% code title="session-validity-ensurer.snippet.ts" %}

```typescript
import { updateDynamoEasyConfig } from '@shiftcoders/dynamo-easy'

updateDynamoEasyConfig({
  sessionValidityEnsurer: (): Promise<void> => {
    // do whatever you need to do to make sure the session is valid
    // and return an Promise<void> when done
    return Promise.resolve()
  },
})

```

{% endcode %}

## Logging

To receive log statements from dynamo-easy you can provide a function

{% code title="log-receiver.snippet.ts" %}

```typescript
import { LogInfo, updateDynamoEasyConfig } from '@shiftcoders/dynamo-easy'

updateDynamoEasyConfig({
  logReceiver: (logInfo: LogInfo) => {
    const msg = `[${logInfo.level}] ${logInfo.timestamp} ${logInfo.className} (${
      logInfo.modelConstructor
      }): ${logInfo.message}`
    console.debug(msg, logInfo.data)
  }
})

```

{% endcode %}

## TableNameResolver

To use different table names per stage you can provide the tableNameResolver function.

This function will receive the default table name (either resolved using the model name or custom value when a tableName was provided in the @Model decorator) and needs to return the extended table name as string.

{% code title="table-name-resolver.snippet.ts" %}

```typescript
import { TableNameResolver, updateDynamoEasyConfig } from '@shiftcoders/dynamo-easy'

const myTableNameResolver: TableNameResolver = (tableName: string) => {
  return `myPrefix-${tableName}`
}

updateDynamoEasyConfig({
  tableNameResolver: myTableNameResolver
})
```

{% endcode %}

## DateMapper

If you want to use a different type for the @DateProperty decorator (eg. Moment or DayJS) you need to define a custom mapper and register it in dynamo-easy easy config.

{% code title="date-mapper.snippet.ts" %}

```typescript
import { updateDynamoEasyConfig } from '@shiftcoders/dynamo-easy'
import { dateToNumberMapper } from '../models'

updateDynamoEasyConfig({
  dateMapper: dateToNumberMapper
})
```

{% endcode %}

{% content-ref url="/pages/-LWAWOtE2gNKYePVgB1r" %}
[CustomMapper](/dynamo-easy/api/model/custommapper.md)
{% endcontent-ref %}
