@gotamedia/aws
Advanced tools
+17
| export type AWS_ERROR_OPTIONS = { | ||
| cause: Error; | ||
| }; | ||
| declare class AWSError extends Error { | ||
| constructor(message: string, options?: AWS_ERROR_OPTIONS); | ||
| } | ||
| declare class LambdaError extends AWSError { | ||
| } | ||
| declare class S3Error extends AWSError { | ||
| } | ||
| declare class SNSError extends AWSError { | ||
| } | ||
| declare class SQSError extends AWSError { | ||
| } | ||
| declare class SSMError extends AWSError { | ||
| } | ||
| export { AWSError, LambdaError, S3Error, SNSError, SQSError, SSMError, }; |
+25
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.SSMError = exports.SQSError = exports.SNSError = exports.S3Error = exports.LambdaError = exports.AWSError = void 0; | ||
| class AWSError extends Error { | ||
| constructor(message, options) { | ||
| super(message, options); | ||
| this.name = this.constructor.name; | ||
| } | ||
| } | ||
| exports.AWSError = AWSError; | ||
| class LambdaError extends AWSError { | ||
| } | ||
| exports.LambdaError = LambdaError; | ||
| class S3Error extends AWSError { | ||
| } | ||
| exports.S3Error = S3Error; | ||
| class SNSError extends AWSError { | ||
| } | ||
| exports.SNSError = SNSError; | ||
| class SQSError extends AWSError { | ||
| } | ||
| exports.SQSError = SQSError; | ||
| class SSMError extends AWSError { | ||
| } | ||
| exports.SSMError = SSMError; |
+17
-0
@@ -5,2 +5,19 @@ # Changelog | ||
| ## [0.2.0](https://bitbucket.org/gotamedia/aws/compare/0.2.0..0.1.2) (2023-06-08) | ||
| ### ⚠ BREAKING CHANGES | ||
| * Removed configure | ||
| * Removed custom error handling and logging and added package specific errors | ||
| ### Features | ||
| * Removed custom error handling and logging and added package specific errors ([95722bb](https://bitbucket.org/gotamedia/aws/commits/95722bb00958e6f87c4e9bf78e0807c95d579888)) | ||
| ### Bug Fixes | ||
| * Removed configure ([55fd8f1](https://bitbucket.org/gotamedia/aws/commits/55fd8f1c1797f143f30a40d1c08396520f61cf54)) | ||
| ## [0.1.2](https://bitbucket.org/gotamedia/aws/compare/0.1.2..0.1.1) (2023-05-31) | ||
@@ -7,0 +24,0 @@ |
+1
-1
| export * from "./services"; | ||
| export * from "./configure"; | ||
| export * from "./errors"; |
+1
-1
@@ -18,2 +18,2 @@ "use strict"; | ||
| __exportStar(require("./services"), exports); | ||
| __exportStar(require("./configure"), exports); | ||
| __exportStar(require("./errors"), exports); |
+1
-1
| { | ||
| "name": "@gotamedia/aws", | ||
| "version": "0.1.2", | ||
| "version": "0.2.0", | ||
| "private": false, | ||
@@ -5,0 +5,0 @@ "description": "Set of AWS helpers for NodeJs Runtime.", |
+1
-25
@@ -18,26 +18,2 @@ # Gota Media AWS | ||
| ## 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 | ||
@@ -312,3 +288,3 @@ Available services: | ||
| ##### silenceXrayContextErrors | ||
| A helper util to silence Xray "Missing AWS Lambda trace data for Xray @Object.contextMissingLogError" | ||
| A helper util to silence Xray "Missing AWS Lambda trace data for Xray @Object.contextMissingLogError" | ||
@@ -315,0 +291,0 @@ **Example:** |
| import type { InvokeCommandInput } from "@aws-sdk/client-lambda"; | ||
| declare const Lambda: import("@aws-sdk/types").Client<any, any, any>; | ||
| declare const invoke: (params: InvokeCommandInput) => Promise<import("@aws-sdk/client-lambda").InvokeCommandOutput | undefined>; | ||
| declare const invoke: (params: InvokeCommandInput) => Promise<import("@aws-sdk/client-lambda").InvokeCommandOutput>; | ||
| export { invoke, Lambda as client }; |
@@ -25,4 +25,3 @@ "use strict"; | ||
| const client_lambda_1 = require("@aws-sdk/client-lambda"); | ||
| const debug_1 = require("../debug"); | ||
| const handleError_1 = require("../handleError"); | ||
| const errors_1 = require("../errors"); | ||
| const Xray_1 = require("./Xray"); | ||
@@ -33,3 +32,2 @@ const Lambda = (0, Xray_1.wrapClient)(new client_lambda_1.LambdaClient({ region: process.env.AWS_REGION })); | ||
| const { FunctionName, Payload, InvocationType = "Event" } = params, filteredParams = __rest(params, ["FunctionName", "Payload", "InvocationType"]); | ||
| (0, debug_1.default)("Invoke Lambda with function name: ", FunctionName, ", type: ", InvocationType, ", payload: ", Payload); | ||
| try { | ||
@@ -41,5 +39,7 @@ const invokeCommand = new client_lambda_1.InvokeCommand(Object.assign({ FunctionName: FunctionName, InvocationType: InvocationType, Payload: Payload ? Buffer.from(JSON.stringify(Payload)) : undefined }, filteredParams)); | ||
| catch (error) { | ||
| (0, handleError_1.default)(error, "Something went wrong while invoking Lambda function"); | ||
| throw new errors_1.LambdaError("Something went wrong while invoking Lambda function", { | ||
| cause: error | ||
| }); | ||
| } | ||
| }); | ||
| exports.invoke = invoke; |
+1
-1
| 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 getObject: (params: GetObjectCommandInput) => Promise<import("@aws-sdk/client-s3").GetObjectCommandOutput>; | ||
| declare const putObject: (params: PutObjectCommandInput) => Promise<void>; | ||
| declare const deleteObject: (params: DeleteObjectCommandInput) => Promise<void>; | ||
| export { getObject, putObject, deleteObject, S3 as client }; |
+10
-8
@@ -25,4 +25,3 @@ "use strict"; | ||
| const client_s3_1 = require("@aws-sdk/client-s3"); | ||
| const debug_1 = require("../debug"); | ||
| const handleError_1 = require("../handleError"); | ||
| const errors_1 = require("../errors"); | ||
| const Xray_1 = require("./Xray"); | ||
@@ -33,3 +32,2 @@ const S3 = (0, Xray_1.wrapClient)(new client_s3_1.S3Client({ region: process.env.AWS_REGION })); | ||
| const { Bucket, Key } = params, filteredParams = __rest(params, ["Bucket", "Key"]); | ||
| (0, debug_1.default)("Get S3 object, BUCKET: ", Bucket, ", KEY: ", Key); | ||
| try { | ||
@@ -41,3 +39,5 @@ const getObjectCommand = new client_s3_1.GetObjectCommand(Object.assign({ Bucket: Bucket, Key: Key }, filteredParams)); | ||
| catch (error) { | ||
| (0, handleError_1.default)(error, "Something went wrong while getting S3 object"); | ||
| throw new errors_1.S3Error("Something went wrong while getting S3 object", { | ||
| cause: error | ||
| }); | ||
| } | ||
@@ -48,3 +48,2 @@ }); | ||
| const { Bucket, Key, Body, ContentType = "application/json" } = params, filteredParams = __rest(params, ["Bucket", "Key", "Body", "ContentType"]); | ||
| (0, debug_1.default)("Put S3 object, BUCKET: ", Bucket, ", KEY: ", Key, ", BODY: ", Body); | ||
| try { | ||
@@ -55,3 +54,5 @@ const putObjectCommand = new client_s3_1.PutObjectCommand(Object.assign({ Bucket: Bucket, Key: Key, Body: Body, ContentType: ContentType }, filteredParams)); | ||
| catch (error) { | ||
| (0, handleError_1.default)(error, "Something went wrong while putting S3 object"); | ||
| throw new errors_1.S3Error("Something went wrong while putting S3 object", { | ||
| cause: error | ||
| }); | ||
| } | ||
@@ -62,3 +63,2 @@ }); | ||
| const { Bucket, Key } = params, filteredParams = __rest(params, ["Bucket", "Key"]); | ||
| (0, debug_1.default)("Delete S3 object, BUCKET: ", Bucket, ", KEY: ", Key); | ||
| try { | ||
@@ -69,5 +69,7 @@ const deleteObjectCommand = new client_s3_1.DeleteObjectCommand(Object.assign({ Bucket: Bucket, Key: Key }, filteredParams)); | ||
| catch (error) { | ||
| (0, handleError_1.default)(error, "Something went wrong while deleteing S3 object"); | ||
| throw new errors_1.S3Error("Something went wrong while deleteing S3 object", { | ||
| cause: error | ||
| }); | ||
| } | ||
| }); | ||
| exports.deleteObject = deleteObject; |
+4
-4
@@ -14,4 +14,3 @@ "use strict"; | ||
| const client_sns_1 = require("@aws-sdk/client-sns"); | ||
| const debug_1 = require("../debug"); | ||
| const handleError_1 = require("../handleError"); | ||
| const errors_1 = require("../errors"); | ||
| const Xray_1 = require("./Xray"); | ||
@@ -21,3 +20,2 @@ const SNS = (0, Xray_1.wrapClient)(new client_sns_1.SNSClient({ region: process.env.AWS_REGION })); | ||
| const publishMessage = (params) => __awaiter(void 0, void 0, void 0, function* () { | ||
| (0, debug_1.default)("Publish SNS message with topic: ", params.TopicArn, ", message: ", params.Message); | ||
| try { | ||
@@ -28,5 +26,7 @@ const publishMessageCommand = new client_sns_1.PublishCommand(params); | ||
| catch (error) { | ||
| (0, handleError_1.default)(error, "Something went wrong while publishing SNS message"); | ||
| throw new errors_1.SNSError("Something went wrong while publishing SNS message", { | ||
| cause: error | ||
| }); | ||
| } | ||
| }); | ||
| exports.publishMessage = publishMessage; |
+7
-6
@@ -14,4 +14,3 @@ "use strict"; | ||
| const client_sqs_1 = require("@aws-sdk/client-sqs"); | ||
| const debug_1 = require("../debug"); | ||
| const handleError_1 = require("../handleError"); | ||
| const errors_1 = require("../errors"); | ||
| const Xray_1 = require("./Xray"); | ||
@@ -21,3 +20,2 @@ const SQS = (0, Xray_1.wrapClient)(new client_sqs_1.SQSClient({ region: process.env.AWS_REGION })); | ||
| const sendMessage = (params) => __awaiter(void 0, void 0, void 0, function* () { | ||
| (0, debug_1.default)("Send SQS message with queue: ", params.QueueUrl, ", message: ", params.MessageBody); | ||
| try { | ||
@@ -28,3 +26,5 @@ const sendMessageCommand = new client_sqs_1.SendMessageCommand(params); | ||
| catch (error) { | ||
| (0, handleError_1.default)(error, "Something went wrong while sending SQS message"); | ||
| throw new errors_1.SQSError("Something went wrong while sending SQS message", { | ||
| cause: error | ||
| }); | ||
| } | ||
@@ -34,3 +34,2 @@ }); | ||
| const sendMessageBatch = (params) => __awaiter(void 0, void 0, void 0, function* () { | ||
| (0, debug_1.default)("Send SQS message batch with queue: ", params.QueueUrl, ", entries: ", params.Entries); | ||
| try { | ||
@@ -41,5 +40,7 @@ const sendMessageBatchCommand = new client_sqs_1.SendMessageBatchCommand(params); | ||
| catch (error) { | ||
| (0, handleError_1.default)(error, "Something went wrong while sending SQS message batch"); | ||
| throw new errors_1.SQSError("Something went wrong while sending SQS message batch", { | ||
| cause: error | ||
| }); | ||
| } | ||
| }); | ||
| exports.sendMessageBatch = sendMessageBatch; |
| import type { GetParameterCommandInput, PutParameterCommandInput } from "@aws-sdk/client-ssm"; | ||
| declare const SSM: import("@aws-sdk/types").Client<any, any, any>; | ||
| declare const getParameter: (params: GetParameterCommandInput) => Promise<string | null>; | ||
| declare const getParameter: (params: GetParameterCommandInput) => Promise<string>; | ||
| declare const putParameter: (params: PutParameterCommandInput) => Promise<void>; | ||
| export { getParameter, putParameter, SSM as client }; |
+8
-10
@@ -25,4 +25,3 @@ "use strict"; | ||
| const client_ssm_1 = require("@aws-sdk/client-ssm"); | ||
| const debug_1 = require("../debug"); | ||
| const handleError_1 = require("../handleError"); | ||
| const errors_1 = require("../errors"); | ||
| const Xray_1 = require("./Xray"); | ||
@@ -33,3 +32,2 @@ const SSM = (0, Xray_1.wrapClient)(new client_ssm_1.SSMClient({ region: process.env.AWS_REGION })); | ||
| const { Name } = params, filteredParams = __rest(params, ["Name"]); | ||
| (0, debug_1.default)("Get SSM patameter with name: ", Name); | ||
| try { | ||
@@ -39,5 +37,3 @@ const getParameterCommand = new client_ssm_1.GetParameterCommand(Object.assign({ Name: Name }, filteredParams)); | ||
| if (!(Parameter === null || Parameter === void 0 ? void 0 : Parameter.Value)) { | ||
| (0, debug_1.default)("Got invalid SSM patameter: ", Parameter); | ||
| (0, handleError_1.default)(new Error("Failed to retrieve parameters from SSM, got empty value")); | ||
| return null; | ||
| throw new errors_1.SSMError("Failed to retrieve parameters from SSM, got empty value"); | ||
| } | ||
@@ -47,4 +43,5 @@ return Parameter.Value; | ||
| catch (error) { | ||
| (0, handleError_1.default)(error, "Something went wrong while retrieving parameters from SSM"); | ||
| return null; | ||
| throw new errors_1.SSMError("Something went wrong while retrieving parameters from SSM", { | ||
| cause: error | ||
| }); | ||
| } | ||
@@ -55,3 +52,2 @@ }); | ||
| const { Name, Value, Type = "String", Overwrite = true } = params, filteredParams = __rest(params, ["Name", "Value", "Type", "Overwrite"]); | ||
| (0, debug_1.default)("Put SSM patameter with name: ", Name, ", value: ", Value, ", type: ", Type); | ||
| try { | ||
@@ -62,5 +58,7 @@ const putParameterCommand = new client_ssm_1.PutParameterCommand(Object.assign({ Name: Name, Value: Value, Type: Type, Overwrite: Overwrite }, filteredParams)); | ||
| catch (error) { | ||
| (0, handleError_1.default)(error, "Something went wrong while storing parameter value in SSM"); | ||
| throw new errors_1.SSMError("Something went wrong while storing parameter value in SSM", { | ||
| cause: error | ||
| }); | ||
| } | ||
| }); | ||
| exports.putParameter = putParameter; |
| export type AWS_SERVICES_CONFIG_Type = { | ||
| debug?: boolean; | ||
| throwErrors?: boolean; | ||
| outputErrors?: boolean; | ||
| }; | ||
| declare let AWS_SERVICES_CONFIG: AWS_SERVICES_CONFIG_Type; | ||
| declare const configure: (config: AWS_SERVICES_CONFIG_Type) => void; | ||
| export { AWS_SERVICES_CONFIG, configure }; |
-13
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.configure = exports.AWS_SERVICES_CONFIG = void 0; | ||
| let AWS_SERVICES_CONFIG = { | ||
| debug: false, | ||
| throwErrors: false, | ||
| outputErrors: true | ||
| }; | ||
| exports.AWS_SERVICES_CONFIG = AWS_SERVICES_CONFIG; | ||
| const configure = (config) => { | ||
| exports.AWS_SERVICES_CONFIG = AWS_SERVICES_CONFIG = Object.assign(Object.assign({}, AWS_SERVICES_CONFIG), config); | ||
| }; | ||
| exports.configure = configure; |
| declare function debug(...args: any[]): void; | ||
| export default debug; |
-10
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const configure_1 = require("./configure"); | ||
| function debug(...args) { | ||
| if (configure_1.AWS_SERVICES_CONFIG.debug) { | ||
| console.log("AWS Services:"); | ||
| console.log("\t", ...args); | ||
| } | ||
| } | ||
| exports.default = debug; |
| declare const handleError: (error: Error, info?: any) => void; | ||
| export default handleError; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const utils_1 = require("@gotamedia/utils"); | ||
| const configure_1 = require("./configure"); | ||
| const handleError = (error, info) => { | ||
| if (configure_1.AWS_SERVICES_CONFIG.outputErrors) { | ||
| (0, utils_1.logError)(error, info); | ||
| } | ||
| if (configure_1.AWS_SERVICES_CONFIG.throwErrors) { | ||
| throw error; | ||
| } | ||
| }; | ||
| exports.default = handleError; |
31319
-5.98%23
-14.81%362
-1.36%325
-6.88%