npm package: @stone-ton/aws-wrappers
Description: Códigos reutilizáveis de serviços aws
Author: Emerson Katsumi Matsumoto
Latest version: 1.4.0

# `@stone-ton/aws-wrappers`

Lib para fazer wrapper de serviços da AWS

## Lambda Invoke

```javascript
const { lambdaInvoke } = require('@stone-ton/aws-wrappers');

const user = await lambdaInvoke<User>({
  FunctionName: 'lambda-test',
  InvocationType: 'RequestResponse',
  Payload: JSON.stringify({
    foo: 'bar',
  }),
})
```


## SQS Send Message

```javascript
const { sqsSendMessage } = require('@stone-ton/aws-wrappers');

await sqsSendMessage({
  QueueUrl: process.env.SQS_PAYMENT_PROVIDER_POSTBACK as string,
  MessageGroupId: transaction_id,
  MessageBody: JSON.stringify(messageBody),
})
```

## SQS Send Message Batch

```javascript
const { sqsSendMessageBatch } = require('@stone-ton/aws-wrappers');

await sqsSendMessageBatch({
  QueueUrl: process.env.SQS_PAYMENT_PROVIDER_POSTBACK as string,
  Entries: [
    {
      Id: transaction_id,
      MessageGroupId: group_id,
      MessageBody: JSON.stringify(messageBody),
    }
  ]
})
```

## Dynamo Get
```javascript
const { dynamoGet } = require('@stone-ton/aws-wrappers');

await dynamoGet({
  TableName: process.env.DYNAMO_TABLE_SMUSER_COMPANIES as string,
  Key: {
    id: companyId,
  },
})
```

## Dynamo Query
```javascript
const { dynamoQuery } = require('@stone-ton/aws-wrappers');

await dynamoQuery({
  TableName: process.env.DYNAMO_TABLE_TONZILLA_USER_ACCOUNT as string,
  IndexName: 'user-id-index',
  KeyConditionExpression: 'user_id = :user_id',
  ExpressionAttributeValues: {
    ':user_id': user_id,
  },
})
```

## Dynamo Put
```javascript
const { dynamoPut, removeEmpty } = require('@stone-ton/aws-wrappers');

await dynamoPut({
  TableName: process.env.DYNAMO_TABLE_EXTRATON_SALES as string,
  Item: removeEmpty(data),
})
```

## Dynamo Update
```javascript
const {
  dynamoUpdate,
  removeEmpty,
  createUpdateExpression,
  createExpressionAttributeNames,
  createExpressionAttributeValues,
} = require('@stone-ton/aws-wrappers');

const { id, ...newUserData } = {
  ...removeEmpty(newUser),
  updated_at: new Date().toISOString(),
}

await dynamoUpdate({
  TableName: 'table-name',
  Key: {
    id,
  },
  UpdateExpression: createUpdateExpression(newUserData),
  ExpressionAttributeNames: createExpressionAttributeNames(newUserData),
  ExpressionAttributeValues: createExpressionAttributeValues(newUserData),
})
```

## Dynamo Delete
```javascript
const { dynamoDelete } = require('@stone-ton/aws-wrappers');

await dynamoDelete({
  TableName: 'table-name',
  Key: {
    foo: 'bar',
  },
})
```

## Dynamo Transact Write
```javascript
const { dynamoTransactWrite, removeEmpty } = require('@stone-ton/aws-wrappers');

await dynamoTransactWrite({
  TransactItems: [
    {
      Put: {
        TableName: process.env.DYNAMO_TABLE_EXTRATON_REPORTS as string,
        Item: removeEmpty(data.data_event)
      },
    },
    {
      Put: {
        TableName: process.env.DYNAMO_TABLE_EXTRATON_EVENTS as string,
        Item: removeEmpty(data),
      },
    },
  ],
})
```

## Redis Get

```javascript
const { default: RedisProvider } = require('@stone-ton/aws-wrappers/lib/redis')

const redis = new RedisProvider({
  host: 'resis-host-test',
  port: 6379,
  password: 'resis-password-test',
  cluster: true,
  tls: true,
  abortOnError: false,
})

await redis.get('item-key')
```

## Redis Set

```javascript
const { default: RedisProvider } = require('@stone-ton/aws-wrappers/lib/redis')

const redis = new RedisProvider({
  host: 'resis-host-test',
  port: 6379,
  password: 'resis-password-test',
  cluster: true,
  tls: true,
  abortOnError: false,
})

await redis.set({
  key: 'item-key',
  value: 'item-value',
  expirationInSeconds: 'item-ttl',
})
```