Skip to content

Commit

Permalink
feat: [#188172364] connect businesses table with lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
aadedejifearless committed Oct 4, 2024
1 parent 3b86106 commit 1c89434
Show file tree
Hide file tree
Showing 15 changed files with 594 additions and 43 deletions.
101 changes: 101 additions & 0 deletions api/businesses-dynamodb-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"TableName": "businesses-table-dev",
"AttributeDefinitions": [
{
"AttributeName": "businessId",
"AttributeType": "S"
},
{
"AttributeName": "businessName",
"AttributeType": "S"
},
{
"AttributeName": "naicsCode",
"AttributeType": "S"
},
{
"AttributeName": "industry",
"AttributeType": "S"
},
{
"AttributeName": "encryptedTaxId",
"AttributeType": "S"
}
],
"KeySchema": [
{
"AttributeName": "businessId",
"KeyType": "HASH"
}
],
"GlobalSecondaryIndexes": [
{
"IndexName": "BusinessName",
"KeySchema": [
{
"AttributeName": "businessName",
"KeyType": "HASH"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"ProvisionedThroughput": {
"ReadCapacityUnits": 25,
"WriteCapacityUnits": 25
}
},
{
"IndexName": "NaicsCode",
"KeySchema": [
{
"AttributeName": "naicsCode",
"KeyType": "HASH"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"ProvisionedThroughput": {
"ReadCapacityUnits": 25,
"WriteCapacityUnits": 25
}
},
{
"IndexName": "Industry",
"KeySchema": [
{
"AttributeName": "industry",
"KeyType": "HASH"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"ProvisionedThroughput": {
"ReadCapacityUnits": 25,
"WriteCapacityUnits": 25
}
},
{
"IndexName": "EncryptedTaxId",
"KeySchema": [
{
"AttributeName": "encryptedTaxId",
"KeyType": "HASH"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"ProvisionedThroughput": {
"ReadCapacityUnits": 25,
"WriteCapacityUnits": 25
}
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 25,
"WriteCapacityUnits": 25
}
}
103 changes: 102 additions & 1 deletion api/jest-dynalite-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module.exports = {
tables: [
{
TableName: "users-table-test",
AttributeDefinitions: [
{
AttributeName: "userId",
Expand Down Expand Up @@ -41,7 +42,107 @@ module.exports = {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
TableName: "users-table-test",
},
{
TableName: "businesses-table-test",
AttributeDefinitions: [
{
AttributeName: "businessId",
AttributeType: "S",
},
{
AttributeName: "businessName",
AttributeType: "S",
},
{
AttributeName: "naicsCode",
AttributeType: "S",
},
{
AttributeName: "industry",
AttributeType: "S",
},
{
AttributeName: "encryptedTaxId",
AttributeType: "S",
},
],
KeySchema: [
{
AttributeName: "businessId",
KeyType: "HASH",
},
],
GlobalSecondaryIndexes: [
{
IndexName: "BusinessName",
KeySchema: [
{
AttributeName: "businessName",
KeyType: "HASH",
},
],
Projection: {
ProjectionType: "ALL",
},
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
},
{
IndexName: "NaicsCode",
KeySchema: [
{
AttributeName: "naicsCode",
KeyType: "HASH",
},
],
Projection: {
ProjectionType: "ALL",
},
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
},
{
IndexName: "Industry",
KeySchema: [
{
AttributeName: "industry",
KeyType: "HASH",
},
],
Projection: {
ProjectionType: "ALL",
},
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
},
{
IndexName: "EncryptedTaxId",
KeySchema: [
{
AttributeName: "encryptedTaxId",
KeyType: "HASH",
},
],
Projection: {
ProjectionType: "ALL",
},
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
},
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
},
],
port: 8002,
Expand Down
17 changes: 15 additions & 2 deletions api/serverless.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dynamoDbSchema from "@businessnjgovnavigator/api/dynamodb-schema.json";
import businessesDynamoDbSchema from "@businessnjgovnavigator/api/businesses-dynamodb-schema.json";
import usersDynamoDbSchema from "@businessnjgovnavigator/api/users-dynamodb-schema.json";
import encryptTaxId from "@functions/encryptTaxId";
import express from "@functions/express";
import githubOauth2 from "@functions/githubOauth2";
Expand Down Expand Up @@ -35,6 +36,7 @@ const airtableUsersTable = process.env.AIRTABLE_USERS_TABLE || "";

const region = "us-east-1";
const usersTable = `users-table-${stage}`;
const businessesTable = `businesses-table-${stage}`;
const ssmLocation = stage === "local" ? "dev" : stage;

const contentEnv = "content";
Expand Down Expand Up @@ -155,7 +157,9 @@ const serverlessConfiguration: AWS = {
],
Resource: [
`arn:aws:dynamodb:${region}:*:table/${usersTable}`,
`arn:aws:dynamodb:${region}:*:table/${businessesTable}`,
`arn:aws:dynamodb:${region}:*:table/${usersTable}/index/*`,
`arn:aws:dynamodb:${region}:*:table/${businessesTable}/index/*`,
],
},
{
Expand Down Expand Up @@ -236,6 +240,7 @@ const serverlessConfiguration: AWS = {
STAGE: stage,
USE_FAKE_SELF_REG: useFakeSelfReg,
USERS_TABLE: usersTable,
BUSINESSES_TABLE: businessesTable,
} as AwsLambdaEnvironment,
logRetentionInDays: 180,
},
Expand Down Expand Up @@ -339,10 +344,18 @@ if (!env.CI || stage === "local") {
Type: "AWS::DynamoDB::Table",
DeletionPolicy: "Retain",
Properties: {
...dynamoDbSchema,
...usersDynamoDbSchema,
TableName: usersTable,
},
},
BusinessesDynamoDBTable: {
Type: "AWS::DynamoDB::Table",
DeletionPolicy: "Retain",
Properties: {
...businessesDynamoDbSchema,
TableName: businessesTable,
},
},
GatewayResponseDefault4XX: {
Type: "AWS::ApiGateway::GatewayResponse",
Properties: {
Expand Down
Loading

0 comments on commit 1c89434

Please sign in to comment.