@stone-ton/aws-wrappers
v1.4.0
Published
Códigos reutilizáveis de serviços aws
Downloads
428
Readme
@stone-ton/aws-wrappers
Lib para fazer wrapper de serviços da AWS
Lambda Invoke
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
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
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
const { dynamoGet } = require('@stone-ton/aws-wrappers');
await dynamoGet({
TableName: process.env.DYNAMO_TABLE_SMUSER_COMPANIES as string,
Key: {
id: companyId,
},
})
Dynamo Query
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
const { dynamoPut, removeEmpty } = require('@stone-ton/aws-wrappers');
await dynamoPut({
TableName: process.env.DYNAMO_TABLE_EXTRATON_SALES as string,
Item: removeEmpty(data),
})
Dynamo Update
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
const { dynamoDelete } = require('@stone-ton/aws-wrappers');
await dynamoDelete({
TableName: 'table-name',
Key: {
foo: 'bar',
},
})
Dynamo Transact Write
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
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
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',
})