Skip to content

Commit

Permalink
Merge pull request #42 from bu-ist/delete-dynamodb-table
Browse files Browse the repository at this point in the history
Change label of primary key.
  • Loading branch information
jdub233 authored Nov 13, 2023
2 parents 14afb93 + 02c62ef commit 5b96ede
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ process.env.DYNAMODB_TABLE = 'test-table';

// Mock the ddb client.
ddbMock.on(GetCommand, {
Key: { SiteAndGroupKey: 'PROTECTED_SITES' },
Key: { PK: 'PROTECTED_SITES' },
}).resolves({
Item: {
ProtectedSites: JSON.stringify([
Expand All @@ -22,7 +22,7 @@ ddbMock.on(GetCommand, {
]),
},
}).on(GetCommand, {
Key: { SiteAndGroupKey: 'example.host.bu.edu/protected#somegroup' },
Key: { PK: 'example.host.bu.edu/protected#somegroup' },
}).resolves({
Item: {
rules: JSON.stringify({
Expand Down
2 changes: 1 addition & 1 deletion src/authorizeRequest/authorizeRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async function authorizeRequest(userRequest, siteRule) {
// to avoid INFO Failed to find the group in DynamoDB for group: entire-bu-community
const { Item } = await dynamoDb.get({
TableName: tableName,
Key: { SiteAndGroupKey: siteAndGroupKey },
Key: { PK: siteAndGroupKey },
});

if (Item == null) {
Expand Down
6 changes: 3 additions & 3 deletions src/authorizeRequest/authorizeRequest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ process.env.DYNAMODB_TABLE = 'test-table';

// Mock the ddb client.
ddbMock.on(GetCommand, {
Key: { SiteAndGroupKey: 'example.host.bu.edu/somesite#somegroup' },
Key: { PK: 'example.host.bu.edu/somesite#somegroup' },
}).resolves({
Item: {
rules: JSON.stringify({
Expand All @@ -22,7 +22,7 @@ ddbMock.on(GetCommand, {
}),
},
}).on(GetCommand, {
Key: { SiteAndGroupKey: 'example.host.bu.edu/somesite#othergroup' },
Key: { PK: 'example.host.bu.edu/somesite#othergroup' },
}).resolves({
Item: {
rules: JSON.stringify({
Expand All @@ -32,7 +32,7 @@ ddbMock.on(GetCommand, {
}),
},
}).on(GetCommand, {
Key: { SiteAndGroupKey: 'example.host.bu.edu/#somegroup' },
Key: { PK: 'example.host.bu.edu/#somegroup' },
}).resolves({
Item: {
rules: JSON.stringify({
Expand Down
2 changes: 1 addition & 1 deletion src/authorizeRequest/getProtectedSites.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function getProtectedSites() {

const { Item } = await dynamoDb.get({
TableName: tableName,
Key: { SiteAndGroupKey: 'PROTECTED_SITES' },
Key: { PK: 'PROTECTED_SITES' },
});

const { ProtectedSites } = Item;
Expand Down
2 changes: 1 addition & 1 deletion src/getOrCreateObject/resizeAndSave/lookupCustomCrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function lookupCustomCrop(url, domain, sizeMatch) {
const params = {
TableName: tableName,
Key: {
SiteAndGroupKey: `SIZES#${domain}${siteName}`,
PK: `SIZES#${domain}${siteName}`,
},
};

Expand Down
11 changes: 9 additions & 2 deletions template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ Resources:
Timeout: 30
Environment:
Variables:
DYNAMODB_TABLE: !Ref AccessControlDynamoDB
DYNAMODB_TABLE: !Ref TempAccessControlDynamoDB
ORIGINAL_BUCKET: !Ref S3Bucket
# The function needs permission to call back to the S3 Object Lambda Access Point with the WriteGetObjectResponse.
Policies:
- DynamoDBReadPolicy:
TableName: !Ref AccessControlDynamoDB
TableName: !Ref TempAccessControlDynamoDB
- S3CrudPolicy:
BucketName: !Ref S3Bucket
- Statement:
Expand All @@ -169,6 +169,13 @@ Resources:
Type: String
TableName: !Sub ${AWS::StackName}-AccessControl

TempAccessControlDynamoDB:
Type: AWS::Serverless::SimpleTable
Properties:
PrimaryKey:
Name: PK
Type: String
TableName: !Sub ${AWS::StackName}-TempAccessControl

Outputs:
S3BucketName:
Expand Down

0 comments on commit 5b96ede

Please sign in to comment.