Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@gotamedia/aws

Package Overview
Dependencies
Maintainers
3
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gotamedia/aws - npm Package Compare versions

Comparing version
0.0.8
to
0.1.0
+12
-0
CHANGELOG.md

@@ -5,2 +5,14 @@ # Changelog

## [0.1.0](https://bitbucket.org/gotamedia/aws/compare/0.1.0..0.0.8) (2023-05-29)
### ⚠ BREAKING CHANGES
* Introduced @gotamedia/aws package.
### Features
* Added getObject() to S3 service. ([be8f2e9](https://bitbucket.org/gotamedia/aws/commits/be8f2e9d3427b8dee00b33bd3af19faf32615131))
* Introduced @gotamedia/aws package. ([707c059](https://bitbucket.org/gotamedia/aws/commits/707c0598d11d55e7a9c843537a407f22ca03811b))
## [0.0.8](https://bitbucket.org/gotamedia/aws/compare/0.0.8..0.0.7) (2023-05-26)

@@ -7,0 +19,0 @@

+1
-1
{
"name": "@gotamedia/aws",
"version": "0.0.8",
"version": "0.1.0",
"private": false,

@@ -5,0 +5,0 @@ "description": "Set of AWS helpers for NodeJs Runtime.",

+318
-1
# Gota Media AWS
Set of AWS helpers for NodeJs Runtime.
A light-weight wrapper around some of AWS JS-SDK v3 AWS.
## Usage
```sh
npm install @gotamedia/aws
```
```ts
import { invoke } from "@gotamedia/aws/services/Lambda"
const handler = () => {
invoke(...)
}
```
## Configure
In your lambda, import configure() from `@gotamedia/aws/configure` and make sure to call it bafore your handler
**Example:**
```ts
import configure from "@gotamedia/aws/configure"
configure({
outputErrors: true,
throwErrors: true
})
const handler = async () => {
...
}
```
##### configure()
| property | type | default | required | description |
|--------------|---------|---------|----------|------------------------------------------------------------------------------------------------|
| debug | boolean | false | | A debug flag, if set to true AWS Layer will start outputting helpful logs for all it's methods |
| throwErrors | boolean | false | | Throw all caught errors from AWS SDK |
| outputErrors | boolean | true | | Output all caught errors from AWS SDK |
## Services
Available services:
* Lambda
* S3
* SNS
* SQS
* SSM
* Xray
## Utils
Available utils:
* silenceXrayContextErrors
> **_NOTE:_** All services exports thier own client: `import { client as LambdaClient } from "@gotamedia/aws/services/Lambda"`
### Lambda
A light-weight wrapper arround `@aws-sdk/clients-lambda` wrapped with Xray traces
#### Available methods:
##### invoke()
| param | type | default | required | description |
|--------|------------------------------|-----------|----------|--------------------------------------|
| first | InvokeCommandInput | undefined | x | AWS Lambda InvokeCommandInput params |
**Example:**
```ts
import { invoke } from "@gotamedia/aws/services/Lambda"
import type { InvokeCommandInput } from "@aws-sdk/client-lambda"
const handler = async () => {
const invokeCommandInput: InvokeCommandInput = {
FunctionName: "my-awesome-function",
InvocationType: "Event"
}
const response = await invoke(invokeCommandInput)
}
```
### S3
A light-weight wrapper arround `@aws-sdk/clients-s3` wrapped with Xray traces
#### Available methods:
##### getObject()
| param | type | default | required | description |
|--------|---------------------------------|-----------|----------|-------------------------------------|
| first | GetObjectCommandInput | undefined | x | AWS S3 GetObjectCommandInput params |
**Example:**
```ts
import { getObject } from "@gotamedia/aws/services/S3"
import type { GetObjectCommandInput } from "@aws-sdk/client-s3"
const handler = async () => {
const getObjectCommandInput: GetObjectCommandInput = {
Bucket: "my-awesome-bucket",
Key: "my-awesome-key"
}
const response = await getObject(getObjectCommandInput)
}
```
### S3
A light-weight wrapper arround `@aws-sdk/clients-s3` wrapped with Xray traces
#### Available methods:
##### putObject()
| param | type | default | required | description |
|--------|---------------------------------|-----------|----------|-------------------------------------|
| first | PutObjectCommandInput | undefined | x | AWS S3 PutObjectCommandInput params |
**Example:**
```ts
import { putObject } from "@gotamedia/aws/services/S3"
import type { PutObjectCommandInput } from "@aws-sdk/client-s3"
const handler = async () => {
const putObjectCommandInput: PutObjectCommandInput = {
Bucket: "my-awesome-bucket",
Key: "my-awesome-key",
Body: JSON.stringify({
id: "123-321",
awesome: true,
ContentType: "application/json"
})
}
const response = await putObject(putObjectCommandInput)
}
```
### S3
A light-weight wrapper arround `@aws-sdk/clients-s3` wrapped with Xray traces
#### Available methods:
##### deleteObject()
| param | type | default | required | description |
|--------|------------------------------------|-----------|----------|----------------------------------------|
| first | DeleteObjectCommandInput | undefined | x | AWS S3 DeleteObjectCommandInput params |
**Example:**
```ts
import { deleteObject } from "@gotamedia/aws/services/S3"
import type { DeleteObjectCommandInput } from "@aws-sdk/client-s3"
const handler = async () => {
const deleteObjectCommandInput: DeleteObjectCommandInput = {
Bucket: "my-awesome-bucket",
Key: "my-awesome-key"
}
const response = await deleteObject(deleteObjectCommandInput)
}
```
### SNS
A light-weight wrapper arround `@aws-sdk/clients-sns` wrapped with Xray traces
#### Available methods:
##### publishMessage()
| param | type | default | required | description |
|--------|---------------------|-----------|----------|------------------------------------|
| first | PublishCommandInput | undefined | x | AWS SNS PublishCommandInput params |
**Example:**
```ts
import { publishMessage } from "@gotamedia/aws/services/SNS"
import type { PublishCommandInput } from "@aws-sdk/client-sns"
const handler = async () => {
const publishMessageCommandInput: PublishCommandInput = {
TopicArn: "my-awesome-topic",
Message: "Hello from @gotamedia/aws package!"
}
await publishMessage(publishMessageCommandInput)
}
```
### SQS
A light-weight wrapper arround `@aws-sdk/clients-sqs` wrapped with Xray traces
#### Available methods:
##### sendMessage()
| param | type | default | required | description |
|--------|-------------------------|-----------|----------|----------------------------------------|
| first | SendMessageCommandInput | undefined | x | AWS SQS SendMessageCommandInput params |
**Example:**
```ts
import { sendMessage } from "@gotamedia/aws/services/SQS"
import type { SendMessageCommandInput } from "@aws-sdk/client-sqs"
const handler = async () => {
const sendMessageCommandInput: SendMessageCommandInput = {
QueueUrl: "my-awesome-queue",
MessageBody: "Hello from @gotamedia/aws package!"
}
await sendMessage(sendMessageCommandInput)
}
```
##### sendMessageBatch()
| param | type | default | required | description |
|--------|------------------------------|-----------|----------|---------------------------------------------|
| first | SendMessageBatchCommandInput | undefined | x | AWS SQS SendMessageBatchCommandInput params |
**Example:**
```ts
import { sendMessageBatch } from "@gotamedia/aws/services/SQS"
import type { SendMessageBatchCommandInput } from "@aws-sdk/client-sqs"
const handler = async () => {
const sendMessageBatchCommandInput: SendMessageBatchCommandInput = {
QueueUrl: "my-awesome-queue",
Entries: [
{
Id: "123-321",
MessageBody: "1: Hello from @gotamedia/aws package!"
},
{
Id: "321-123",
MessageBody: "2: Hello from @gotamedia/aws package!"
}
]
}
await sendMessageBatch(sendMessageBatchCommandInput)
}
```
### SSM
A light-weight wrapper arround `@aws-sdk/clients-ssm` wrapped with Xray traces
#### Available methods:
##### getParameter()
| param | type | default | required | description |
|-------|--------------------------|-----------|----------|-----------------------------------------|
| first | GetParameterCommandInput | undefined | x | AWS SSM GetParameterCommandInput params |
**Example:**
```ts
import { getParameter } from "@gotamedia/aws/services/SSM"
import type { GetParameterCommandInput } from "@aws-sdk/client-ssm"
const handler = async () => {
const getParameterCommandInput: GetParameterCommandInput = {
Name: "my-awesome-parameter"
}
const parameterValue = await getParameter(getParameterCommandInput)
}
```
##### putParameter()
| param | type | default | required | description |
|--------|---------------------|-----------|----------|-----------------------------------------|
| first | PutParameterCommand | undefined | x | AWS SSM PutParameterCommand params |
**Example:**
```ts
import { putParameter } from "@gotamedia/aws/services/SSM"
import type { PutParameterCommand } from "@aws-sdk/client-ssm"
const handler = async () => {
const putParameterCommandInput: PutParameterCommand = {
Name: "my-awesome-parameter",
Value: "my-awesome-value",
Type: "String"
}
await putParameter(putParameterCommandInput)
}
```
### Xray
A helper service to help you wrapping `AWS-SDK V3 Clients` with Xray
#### Available methods:
##### wrapClient()
| param | type | default | required | description |
|-------|------------|-----------|----------|-------------------|
| first | AWS Client | undefined | x | AWS SDK V3 Client |
**Example:**
```ts
import { DynamodbClient } from "@aws-sdk/clients-dynamodb"
import { wrapClient } from "@gotamedia/aws/services/Xray"
const Dynamodb = wrapClient(new DynamodbClient({ region: "eu-north-1" }))
const handler = async () => {
// Use DynamoDB sdk commands...
}
```
#### Available utils:
##### silenceXrayContextErrors
A helper util to silence Xray "Missing AWS Lambda trace data for Xray @Object.contextMissingLogError"
**Example:**
```ts
import "@gotamedia/aws/utils/silenceXrayContextErrors"
const handler = async () => {
...
}
```

@@ -1,5 +0,6 @@

import type { PutObjectCommandInput, DeleteObjectCommandInput } from "@aws-sdk/client-s3";
import type { GetObjectCommandInput, PutObjectCommandInput, DeleteObjectCommandInput } from "@aws-sdk/client-s3";
declare const S3: import("@aws-sdk/types").Client<any, any, any>;
declare const getObject: (params: GetObjectCommandInput) => Promise<import("@aws-sdk/client-s3").GetObjectCommandOutput | undefined>;
declare const putObject: (params: PutObjectCommandInput) => Promise<void>;
declare const deleteObject: (params: DeleteObjectCommandInput) => Promise<void>;
export { putObject, deleteObject, S3 as client };
export { getObject, putObject, deleteObject, S3 as client };

@@ -23,3 +23,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.client = exports.deleteObject = exports.putObject = void 0;
exports.client = exports.deleteObject = exports.putObject = exports.getObject = void 0;
const client_s3_1 = require("@aws-sdk/client-s3");

@@ -31,2 +31,15 @@ const debug_1 = require("../debug");

exports.client = S3;
const getObject = (params) => __awaiter(void 0, void 0, void 0, function* () {
const { Bucket, Key } = params, filteredParams = __rest(params, ["Bucket", "Key"]);
(0, debug_1.default)("Get S3 object, BUCKET: ", Bucket, ", KEY: ", Key);
try {
const getObjectCommand = new client_s3_1.GetObjectCommand(Object.assign({ Bucket: Bucket, Key: Key }, filteredParams));
const response = yield S3.send(getObjectCommand);
return response;
}
catch (error) {
(0, handleError_1.default)(error, "Something went wrong while getting S3 object");
}
});
exports.getObject = getObject;
const putObject = (params) => __awaiter(void 0, void 0, void 0, function* () {

@@ -33,0 +46,0 @@ const { Bucket, Key, Body, ContentType = "application/json" } = params, filteredParams = __rest(params, ["Bucket", "Key", "Body", "ContentType"]);