diff --git a/.zk/notebook.db b/.zk/notebook.db index 521b1e9..4273189 100644 Binary files a/.zk/notebook.db and b/.zk/notebook.db differ diff --git a/zk/DynamoDB CLI commands.md b/zk/DynamoDB CLI commands.md deleted file mode 100644 index 0232764..0000000 --- a/zk/DynamoDB CLI commands.md +++ /dev/null @@ -1,72 +0,0 @@ ---- -id: l045 -title: DynamoDB CLI commands -tags: [AWS, databases, dynamodb] -created: Saturday, June 22, 2024 ---- - -# DynamoDB CLI commands - -## Connecting to a local (Docker)/prod (AWS) DynamoDB instance - -In order to distinguish between local and production accounts you should keep -seperate profiles for each (via `.aws/config` and `.aws/credentials`). - -When connecting to a local DB use the local profile and the local URL. Without -the `--profile` flag, AWS will default to the `default` profile which will -typically be your credentials for accessing AWS on the remote. - -It also sometimes required to add the endpoint-url when working locally: - -``` ---endpoint-url http://localhost:800 - -> When using the commans below locally, assume `--endpoint-url` and `--profile` -> have been appended - -``` - -For example: - -```sh -aws dynamodb list-tables \ ---profile timetracking_dev \ ---endpoint-url http://localhost:800 -``` - -## Delete a table - -```sh -aws dynamodb delete-table \ ---table-name TableName -``` - -## Create table from JSON schema - -```sh -aws dynamodb create-table \ ---cli-input-json file://create-timeentries-table.json \ - -``` - -## Describe the table - -View the table schema: - -```sh - -aws dynamodb describe-table \ ---table-name TimeEntries -``` - -## Scan the table - -```sh -aws dynamodb scan \ ---table-name TimeEntries \ ---output table - - -``` - -## Related notes diff --git a/zk/DynamoDB SDK commands.md b/zk/DynamoDB SDK commands.md deleted file mode 100644 index 4f4b0ae..0000000 --- a/zk/DynamoDB SDK commands.md +++ /dev/null @@ -1,64 +0,0 @@ ---- -id: 8b6h -title: DynamoDB SDK commands -tags: [AWS, databases, dynamodb] -created: Sunday, June 23, 2024 ---- - -# DynamoDB SDK commands - -The following commands are for using `@aws-sdk/client-dynamodb` (the JS SDK). - -## Create client - -```js -import DynamoDBClient from "@aws-sdk/client-dynamodb"; - -const client = new DynamoDBClient({ - region: "eu-west-2", - accessKeyId: process.env.ACCESS_KEY_ID, - secretAccessKey: process.env.ACCESS_KEY_ID, -}); -``` - -### DynamoDB Document Client - -The Document Client returns the data as a standard JSON document in the manner -of a document-based NoSQL database. Without it, DynamoDB will return the data -with type data which is unwieldy and hard to parse. - -To transform into a document structure: - -```js -import DynamoDBClient from "@aws-sdk/client-dynamodb"; -import DynamoDBDocumentClient from "@aws-sdk/lib-dynamodb"; - -const client = new DynamoDBClient({ - region: "eu-west-2", - accessKeyId: process.env.ACCESS_KEY_ID, - secretAccessKey: process.env.ACCESS_KEY_ID, -}); - -const dynamoDbDocumentClient = DynamoDBDocumentClient.from(client); -``` - -## Query a table - -Querying is the most performant and cost-effective method since it is an O(1) -lookup against a partition key or secondary index. - -```js -const params = { - TableName: "YourTableName", - KeyConditionExpression: "#pk = :pk", - ExpressionAttributeNames: { "#pk": "PrimaryKeyAttributeName" }, - ExpressionAttributeValues: { ":pk": "PrimaryKeyValue" }, -}; -``` - -## Scan a table - -Scanning is less performant (O(n)) and most expensive since it requires checking -every item in the database. - -## Related notes diff --git a/zk/DynamoDB_CLI_commands.md b/zk/DynamoDB_CLI_commands.md index d837e97..160e650 100644 --- a/zk/DynamoDB_CLI_commands.md +++ b/zk/DynamoDB_CLI_commands.md @@ -16,6 +16,16 @@ When connecting to a local DB use the local profile and the local URL. Without the `--profile` flag, AWS will default to the `default` profile which will typically be your credentials for accessing AWS on the remote. +It also sometimes required to add the endpoint-url when working locally: + +``` +--endpoint-url http://localhost:800 + +> When using the commans below locally, assume `--endpoint-url` and `--profile` +> have been appended + +``` + For example: ```sh @@ -28,8 +38,6 @@ aws dynamodb list-tables \ ```sh aws dynamodb delete-table \ ---profile timetracking_dev \ ---endpoint-url http://localhost:8000 \ --table-name TableName ``` @@ -38,9 +46,25 @@ aws dynamodb delete-table \ ```sh aws dynamodb create-table \ --cli-input-json file://create-timeentries-table.json \ ---profile timetracking_dev \ ---endpoint-url http://localhost:8000 ``` +## Describe the table + +View the table schema: + +```sh + +aws dynamodb describe-table \ +--table-name TimeEntries +``` + +## Scan the table + +```sh +aws dynamodb scan \ +--table-name TimeEntries \ +--output table +``` + ## Related notes diff --git a/zk/DynamoDB_SDK_commands.md b/zk/DynamoDB_SDK_commands.md index 3871e00..11ae5c4 100644 --- a/zk/DynamoDB_SDK_commands.md +++ b/zk/DynamoDB_SDK_commands.md @@ -7,16 +7,75 @@ created: Sunday, June 23, 2024 # DynamoDB SDK commands -The following commands are for using `$aws-sdk/client-dynamodb` (the JS SDK). +The following commands are for using `@aws-sdk/client-dynamodb` (the JS SDK). ## Create client ```js -const params = { +import DynamoDBClient from "@aws-sdk/client-dynamodb"; + +const client = new DynamoDBClient({ region: "eu-west-2", accessKeyId: process.env.ACCESS_KEY_ID, secretAccessKey: process.env.ACCESS_KEY_ID, +}); +``` + +### DynamoDB Document Client + +The Document Client returns the data as a standard JSON document in the manner +of a document-based NoSQL database. Without it, DynamoDB will return the data +with type data which is unwieldy and hard to parse. + +To transform into a document structure: + +```js +import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; +import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb"; + +const client = new DynamoDBClient({ + region: "eu-west-2", + accessKeyId: process.env.ACCESS_KEY_ID, + secretAccessKey: process.env.ACCESS_KEY_ID, +}); + +const dynamoDbDocumentClient = DynamoDBDocumentClient.from(client); +``` + +## Query a table + +Querying is the most performant and cost-effective method since it is an O(1) +lookup against a partition key or secondary index. + +```js +import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb"; + +const params = { + TableName: "YourTableName", + KeyConditionExpression: "#pk = :pk", + ExpressionAttributeNames: { "#pk": "PrimaryKeyAttributeName" }, + ExpressionAttributeValues: { ":pk": "PrimaryKeyValue" }, }; + +const dynamoDbDocumentClient = DynamoDBDocumentClient.from(client); +const data = await dynamoDbDocumentClient.send(new QueryCommand(params)); +console.log(data); +``` + +## Scan a table + +Scanning is less performant (O(n)) and most expensive since it requires checking +every item in the database. + +```js +import { DynamoDBDocumentClient, ScanCommand } from "@aws-sdk/lib-dynamodb"; + +const params = { + TableName: "YourTableName", +}; + +const dynamoDbDocumentClient = DynamoDBDocumentClient.from(client); +const data = await dynamoDbDocumentClient.send(new ScanCommand(params)); ``` ## Related notes diff --git a/zk/Integrated_circuits.md b/zk/Integrated_circuits.md index fec4953..d9717b6 100644 --- a/zk/Integrated_circuits.md +++ b/zk/Integrated_circuits.md @@ -7,8 +7,7 @@ tags: # Integrated circuits An integrated circuit (IC) is a single unit that comprises several logic gates -designed for the easy construction of -[digital circuits](Digital_circuits.md). +designed for the easy construction of [digital circuits](Digital_circuits.md). The terms "integrated circuit" and "chip" are often used interchangeably. An IC puts the gates on a single piece of silicon that has electrical contact @@ -24,5 +23,6 @@ to a breadboard. _An integrated circuit and its use on a breadboard:_ - - +![](../img/integrated-circuit.jpeg) + +![](../img/breadboard-DIP.jpg) diff --git a/zk/LEDs.md b/zk/LEDs.md index c1e1dd7..36d7750 100644 --- a/zk/LEDs.md +++ b/zk/LEDs.md @@ -21,5 +21,5 @@ generic diode circuit symbol: An LED diode lights up when the right amount of current flows through it. A standard LED has a maximum current of 20mA. An appropriate [resistor](Resistance.md#resistors) -must therefore be added to the circuit to ensure the current doesn't exeedd this +must therefore be added to the circuit to ensure the current doesn't exceed this amount.