Skip to content

Commit

Permalink
Merge pull request #23 from boyney123/feat-adding-sqs
Browse files Browse the repository at this point in the history
feat: adding sqs resource to the catalog
  • Loading branch information
boyney123 authored Jan 8, 2024
2 parents 61233c5 + b692517 commit ecea98b
Show file tree
Hide file tree
Showing 28 changed files with 780 additions and 57 deletions.
7 changes: 7 additions & 0 deletions .changeset/beige-donkeys-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@cloudcatalog/cli": patch
"@cloudcatalog/core": patch
"@cloudcatalog/create-catalog": patch
---

feat: adding sqs resource to the catalog
43 changes: 43 additions & 0 deletions examples/default/data/resources/sqs/PaymentProcessingQueue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
name: PaymentProcessingQueue
description: SQS Queue
service: payment-service
AWS:
Arn: arn:aws:sqs:us-west-2:123456789123:PaymentProcessingQueue
Name: PaymentProcessingQueue
CreatedTimestamp: '2022-09-21T12:02:51.000Z'
VisibilityTimeout: 960
MaximumMessageSize: 262144
MessageRetentionPeriod: 345600
DelaySeconds: '0'
ReceiveMessageWaitTimeSeconds: '0'
SqsManagedSseEnabled: 'false'
QueueUrl: https://sqs.us-west-2.amazonaws.com/123456789123/PaymentProcessingQueue
Account: '123456789123'
Service: sqs
catalog:
updatedAt: '2024-01-07T16:40:30.270Z'
parent: sqs
path: PaymentProcessingQueue
owners:
- payment-team
- dboyne
---


## About this SQS queue

The PaymentProcessingQueue acts as a mediator between the payment service and the payment processing system. When a customer initiates a payment, the details are sent to this queue, allowing for asynchronous processing. This means the payment can be processed independently of the customer's session, enhancing system resilience and user experience.

#### Load Management

During peak times, like sales or holiday seasons, the queue efficiently manages the increased load by holding payment requests. This prevents the payment processing service from being overwhelmed, ensuring consistent processing times and system stability.

### Error Handling and Retry Mechanism

In case of failures in the payment processing system, PaymentProcessingQueue can be configured to retry the payment processing after a certain interval or move the failed payment requests to a dead-letter queue for further investigation, thereby reducing the risk of lost transactions.

### Send a message to the SQS queue

<CLICommand>aws sqs send-message --queue-url /QueueUrl/ --message-body "Hello, this is a test message"</CLICommand>

84 changes: 81 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/cloudcatalog-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@aws-sdk/client-lambda": "^3.236.0",
"@aws-sdk/client-sfn": "^3.485.0",
"@aws-sdk/client-sqs": "^3.485.0",
"@aws-sdk/util-arn-parser": "^3.208.0",
"chalk": "4.1.2",
"fs-extra": "^11.1.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/cloudcatalog-cli/src/resources/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as lambda from "./lambda";
import * as states from "./states";
import * as sqs from "./sqs";

type ResourceData = lambda.Data | states.Data;
type ResourceData = lambda.Data | states.Data | sqs.Data;

interface Resource {
getData: (arn: string) => Promise<any>;
Expand All @@ -12,4 +13,5 @@ interface Resource {
export default {
lambda,
states,
sqs,
} as Record<string, Resource>;
90 changes: 90 additions & 0 deletions packages/cloudcatalog-cli/src/resources/sqs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import {
SQSClient,
GetQueueAttributesCommand,
GetQueueUrlCommand,
} from "@aws-sdk/client-sqs";
import { parse } from "@aws-sdk/util-arn-parser";
const client = new SQSClient({});

export interface Data {
name?: string;
description?: string;
AWS: {
Arn: string;
Name: string;
CreatedTimestamp: string | undefined;
VisibilityTimeout: number | undefined;
MaximumMessageSize: number | undefined;
MessageRetentionPeriod: number | undefined;
ReceiveMessageWaitTimeSeconds: string | undefined;
DelaySeconds: string | undefined;
SqsManagedSseEnabled: string | undefined;
QueueUrl: string | undefined;
Account: string;
Service: string;
};
}

// Code that runs to get information about the resource.
export const getData = async (arn: string): Promise<Data> => {
const { resource, accountId } = parse(arn);

const getQueueUrlResponse = await client.send(
new GetQueueUrlCommand({
QueueName: resource,
}),
);

const getQueueAttributesResponse = await client.send(
new GetQueueAttributesCommand({
QueueUrl: getQueueUrlResponse.QueueUrl,
AttributeNames: ["All"],
}),
);

const attributes = getQueueAttributesResponse?.Attributes || {};

const createdTimeStamp = attributes?.CreatedTimestamp
? parseInt(attributes?.CreatedTimestamp)
: undefined;
const parseAttribute = (attribute: any) =>
attribute ? parseInt(attribute) || undefined : undefined;

return {
name: resource,
description: "SQS Queue",
AWS: {
Arn: arn,
Name: resource,
CreatedTimestamp: createdTimeStamp
? new Date(createdTimeStamp * 1000).toISOString()
: undefined,
VisibilityTimeout: parseAttribute(attributes.VisibilityTimeout),
MaximumMessageSize: parseAttribute(attributes.MaximumMessageSize),
MessageRetentionPeriod: parseAttribute(attributes.MessageRetentionPeriod),
DelaySeconds: attributes.DelaySeconds,
ReceiveMessageWaitTimeSeconds: attributes.ReceiveMessageWaitTimeSeconds,
SqsManagedSseEnabled: attributes.SqsManagedSseEnabled,
QueueUrl: getQueueUrlResponse.QueueUrl,
Account: accountId,
Service: "sqs",
},
};
};

// Return the default markdown for new resources
export const getMarkdown = (data: Data): Promise<string> => {
return Promise.resolve(`
## About this SQS queue
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum in ligula et orci pellentesque volutpat. In imperdiet augue sit amet imperdiet ultricies. Etiam eget dui elementum, tempor ligula quis, consectetur eros. Suspendisse sodales mattis ex, nec tempor lorem. Maecenas eget risus suscipit, gravida lectus eu, dictum sapien. Nunc efficitur sem eget dui tempus aliquam.
### Send a message to the SQS queue
<CLICommand>aws sqs send-message --queue-url /QueueUrl/ --message-body "Hello, this is a test message"</CLICommand>
`);
};
export const getFileName = (data: Data): Promise<string> => {
const name = data.AWS.Name || `new-${data.AWS.Service}-file`;
return Promise.resolve(name);
};
2 changes: 1 addition & 1 deletion packages/cloudcatalog-cli/src/utils/cli-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ARN, parse } from "@aws-sdk/util-arn-parser";

const supportedServices = ["lambda", "states"];
const supportedServices = ["lambda", "states", "sqs"];

export const isServiceSupportedByCatalog = (arn: string) => {
const { service } = parse(arn);
Expand Down
Loading

1 comment on commit ecea98b

@vercel
Copy link

@vercel vercel bot commented on ecea98b Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

cloudcatalog-demo – ./packages/cloudcatalog

cloudcatalog-demo.vercel.app
cloudcatalog-demo-davidboyne123.vercel.app
cloudcatalog-demo-git-main-davidboyne123.vercel.app
app.cloudcatalog.dev

Please sign in to comment.