Skip to content

Commit

Permalink
Merge pull request #25 from boyney123/feat-adding-dynamodb
Browse files Browse the repository at this point in the history
Adding DynamoDB
  • Loading branch information
boyney123 authored Jan 13, 2024
2 parents 2e3147d + b1f3bb4 commit 4467823
Show file tree
Hide file tree
Showing 30 changed files with 1,004 additions and 241 deletions.
7 changes: 7 additions & 0 deletions .changeset/gorgeous-dancers-provide.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 DynamoDB resource
53 changes: 53 additions & 0 deletions examples/default/data/resources/dynamodb/user-payments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
name: user-payments
description: Table storing user payments information
service: payment-service
owners:
- dboyne
- payment-team
AWS:
Arn: arn:aws:dynamodb:us-west-2:123456789123:table/user-payments
TableName: user-payments
CreationDateTime: '2022-09-15T09:56:47.097Z'
DeletionProtectionEnabled: false
TableStatus: ACTIVE
TableSizeBytes: 76
StreamSpecification:
StreamEnabled: true
StreamViewType: NEW_AND_OLD_IMAGES
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
AttributeDefinitions:
- AttributeName: id
AttributeType: S
Service: dynamodb
AccountId: 123456789123
catalog:
updatedAt: '2024-01-10T07:48:19.106Z'
parent: dynamodb
path: user-payments
---

## About this table

The user-payments table is an integral component of our payment service, designed to efficiently manage and store transactional data related to user payments. This table serves as a central repository for payment records, ensuring secure and rapid access to transaction details.

## Access patterns

### Retrieve User Transaction History
- **Use Case**: Fetch all transactions made by a specific user.
- **Query Pattern**: Query the table using the userId as the partition key. This returns all items with the matching userId, sorted by transactionId.
- **Example Query**: `SELECT * FROM user-payments WHERE userId = :userId`

### Lookup Specific Transaction

- **Use Case**: Retrieve details of a specific transaction for a user.
- **Query Pattern**: Use both userId (partition key) and transactionId (sort key) to get the specific transaction record.
- **Example Query**: `SELECT * FROM user-payments WHERE userId = :userId AND transactionId = :transactionId`

### Query Transactions Based on Status

- **Use Case**: Identify transactions that are pending, successful, or failed.
- **Implementation**: This may require the use of a Global Secondary Index (GSI) with status as the key if frequent queries are made based on the transaction status.
- **Example Query**: `SELECT * FROM user-payments-index-status WHERE status = :status`
45 changes: 45 additions & 0 deletions examples/default/data/resources/dynamodb/users.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: users
description: Table for storing user information
service: user-service
owners:
- dboyne
- user-team
AWS:
Arn: arn:aws:dynamodb:us-west-2:123456789123:table/user-payments
TableName: user-payments
CreationDateTime: '2022-09-15T09:56:47.097Z'
DeletionProtectionEnabled: false
TableStatus: ACTIVE
TableSizeBytes: 762
StreamSpecification:
StreamEnabled: true
StreamViewType: NEW_AND_OLD_IMAGES
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
AttributeDefinitions:
- AttributeName: id
AttributeType: S
Service: dynamodb
AccountId: 123456789123
catalog:
updatedAt: '2024-01-10T07:48:19.106Z'
parent: dynamodb
path: users
---

## About this table

The users table is an integral part of our infrastructure, serving as the backbone for managing user data. This table is tailored to support various user-related functionalities across our applications, including authentication, profile management, and user activity tracking. It is optimized for high performance and scalability to handle our growing user base.

## Access patterns

### User Authentication:
- Primary access pattern involves querying by `userID` or `email` to retrieve credentials and perform authentication checks.
- Example Query: Retrieve user details by `email` for login purposes.

### Profile Information Retrieval:

- Frequently accessed for displaying user profile information.
- Example Query: Fetch complete user details by `userID` for profile viewing or editing.
101 changes: 98 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 @@ -16,6 +16,7 @@
"awscatalog-cli": "./dist/index.js"
},
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.485.0",
"@aws-sdk/client-lambda": "^3.236.0",
"@aws-sdk/client-sfn": "^3.485.0",
"@aws-sdk/client-sqs": "^3.485.0",
Expand Down
87 changes: 87 additions & 0 deletions packages/cloudcatalog-cli/src/resources/dynamodb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {
DynamoDBClient,
DescribeTableCommand,
TableStatus,
StreamSpecification,
ProvisionedThroughput,
ProvisionedThroughputDescription,
AttributeDefinition,
} from "@aws-sdk/client-dynamodb";
import { parse } from "@aws-sdk/util-arn-parser";
// import chalk from "chalk";
const client = new DynamoDBClient({});

export interface Data {
name?: string;
description?: string;
AWS: {
Arn: string;
TableName?: string;
CreationDateTime: string | undefined;
TableStatus: string | undefined;
DeletionProtectionEnabled?: boolean;
TableSizeBytes?: number | undefined;
StreamSpecification?: StreamSpecification;
ProvisionedThroughput?: ProvisionedThroughputDescription;
AttributeDefinitions?: AttributeDefinition[];
Account: string;
Service: string;
};
}

// arn:aws:dynamodb:us-west-2:123456789123:table/boynestore-users

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

const response = await client.send(
new DescribeTableCommand({
TableName: tableName,
}),
);

const creationDate = response.Table?.CreationDateTime;

console.log("response", JSON.stringify(response, null, 4));

return {
name: response.Table?.TableName,
description: "DynamoDB Table",
AWS: {
Arn: arn,
TableName: response.Table?.TableName,
CreationDateTime: creationDate
? response.Table?.CreationDateTime?.toISOString()
: undefined,
DeletionProtectionEnabled: response.Table?.DeletionProtectionEnabled,
TableStatus: response.Table?.TableStatus,
TableSizeBytes: response.Table?.TableSizeBytes,
StreamSpecification: response.Table?.StreamSpecification,
ProvisionedThroughput: {
ReadCapacityUnits:
response?.Table?.ProvisionedThroughput?.ReadCapacityUnits,
WriteCapacityUnits:
response?.Table?.ProvisionedThroughput?.WriteCapacityUnits,
},
AttributeDefinitions: response.Table?.AttributeDefinitions,
Account: accountId,
Service: "dynamodb",
},
};
};

// Return the default markdown for new resources
export const getMarkdown = (data: Data): Promise<string> => {
return Promise.resolve(`
## About this table
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.
`);
};
export const getFileName = (data: Data): Promise<string> => {
const name = data.AWS.TableName || `new-${data.AWS.TableName}-file`;
return Promise.resolve(name);
};
4 changes: 3 additions & 1 deletion packages/cloudcatalog-cli/src/resources/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as lambda from "./lambda";
import * as states from "./states";
import * as sqs from "./sqs";
import * as dynamodb from "./dynamodb";

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

interface Resource {
getData: (arn: string) => Promise<any>;
Expand All @@ -14,4 +15,5 @@ export default {
lambda,
states,
sqs,
dynamodb,
} as Record<string, Resource>;
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", "sqs"];
const supportedServices = ["lambda", "states", "sqs", "dynamodb"];

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

1 comment on commit 4467823

@vercel
Copy link

@vercel vercel bot commented on 4467823 Jan 13, 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

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

Please sign in to comment.