-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robert Bradley
committed
Jan 7, 2025
1 parent
1b24dd8
commit 32ef68d
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// scripts/create-local-table.js | ||
// This is used to create a test table in our local copy of DynamoDB when the tests run | ||
// This is not used if deploying infrastructure to AWS | ||
const { DynamoDBClient, CreateTableCommand } = require('@aws-sdk/client-dynamodb'); | ||
|
||
(async () => { | ||
try { | ||
const client = new DynamoDBClient({ | ||
region: process.env.AWS_REGION || "us-west-2", | ||
endpoint: process.env.DYNAMODB_ENDPOINT || "http://localhost:8000", | ||
credentials: { | ||
accessKeyId: process.env.AWS_ACCESS_KEY_ID || "FAKE_KEY", | ||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || "FAKE_SECRET", | ||
}, | ||
}); | ||
|
||
const tableName = process.env.DYNAMODB_TABLE_NAME || "RoomsTest"; | ||
|
||
const command = new CreateTableCommand({ | ||
TableName: tableName, | ||
AttributeDefinitions: [ | ||
{ AttributeName: 'id', AttributeType: 'N' }, | ||
], | ||
KeySchema: [ | ||
{ AttributeName: 'id', KeyType: 'HASH' }, | ||
], | ||
ProvisionedThroughput: { | ||
ReadCapacityUnits: 5, | ||
WriteCapacityUnits: 5, | ||
}, | ||
SSESpecification: { | ||
Enabled: true, // server-side encryption | ||
}, | ||
}); | ||
|
||
const result = await client.send(command); | ||
console.log(`Created table '${tableName}' locally.`, result.TableDescription?.TableStatus); | ||
} catch (err) { | ||
console.error('Error creating table locally:', err); | ||
process.exit(1); | ||
} | ||
})(); |