1. Using aws dynamodb with parameter

    TypeScript

    Using AWS DynamoDB involves creating tables to store and retrieve data. When you set up an AWS DynamoDB table with Pulumi, you can define various parameters like the name of the table, the attributes, the key schema, provisioned throughput, and other settings as per your requirements.

    DynamoDB is a fast and flexible NoSQL database service for all applications that need consistent, single-digit millisecond latency at any scale. It is a fully managed cloud database and supports both document and key-value store models.

    Below, you'll find a Pulumi program written in TypeScript that creates a simple AWS DynamoDB table with some basic parameters. These parameters define aspects of the table such as its name, the attributes it will hold, the primary key, and the read and write capacity units which indicate the expected traffic for the table (you may choose to use on-demand pricing model instead).

    import * as aws from "@pulumi/aws"; // Create a DynamoDB table 'music' const table = new aws.dynamodb.Table("music", { // Specify the attributes of the table. These are the columns that each item will have. attributes: [ { name: "Artist", // Name of the attribute type: "S" // Type 'S' stands for string }, { name: "SongTitle", // Name of another attribute type: "S" // Also a string } ], // Define the schema for the primary key, which uniquely identifies each item. keySchema: [ { attributeName: "Artist", keyType: "HASH" // Partition key }, { attributeName: "SongTitle", keyType: "RANGE" // Sort key } ], // Set provisioned throughput for the table; can also be set to use on-demand capacity. billingMode: "PROVISIONED", provisionedThroughput: { readCapacityUnits: 1, writeCapacityUnits: 1 }, // More parameters can be set according to the use-case like tags, global secondary indexes, etc. }); // Export the name of the table export const tableName = table.name;

    In this script:

    • We import the AWS module from Pulumi's AWS package.
    • We create a new DynamoDB table resource called music using aws.dynamodb.Table.
    • The table has two attributes, Artist and SongTitle, both of which are strings.
    • We define the table's keySchema, which consists of a hash type partition key on Artist and a range sort key on SongTitle.
    • The billingMode is set to "PROVISIONED", meaning we specify the number of read and write capacity units. These can be adjusted depending on your application's needs or switched to "PAY_PER_REQUEST" for on-demand capacity pricing.
    • Finally, the name of the table is exported as tableName, which allows the table name to be accessed in other Pulumi stacks or programs.

    Upon running this Pulumi program with pulumi up, Pulumi will perform the deployment, and provided you have the AWS CLI configured with appropriate credentials, it will create the DynamoDB table in your AWS account. You can manage the table, its items, and any additional configurations directly through the AWS Console or using other AWS services programmatically.