|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/aws/aws-cdk-go/awscdk/v2" |
| 5 | + dynamodb "github.com/aws/aws-cdk-go/awscdk/v2/awsdynamodb" |
| 6 | + "github.com/aws/constructs-go/constructs/v10" |
| 7 | + "github.com/aws/aws-sdk-go-v2/aws" |
| 8 | +) |
| 9 | + |
| 10 | +type DynamodbCdkGoStackProps struct { |
| 11 | + awscdk.StackProps |
| 12 | +} |
| 13 | + |
| 14 | +func NewDynamodbCdkGoStack(scope constructs.Construct, id string, props *DynamodbCdkGoStackProps) awscdk.Stack { |
| 15 | + var sprops awscdk.StackProps |
| 16 | + if props != nil { |
| 17 | + sprops = props.StackProps |
| 18 | + } |
| 19 | + stack := awscdk.NewStack(scope, &id, &sprops) |
| 20 | + this := stack |
| 21 | + table := dynamodb.NewTable(this, aws.String("table"), &dynamodb.TableProps{ |
| 22 | + PartitionKey: &dynamodb.Attribute{ |
| 23 | + Name: aws.String("username"), |
| 24 | + Type: dynamodb.AttributeType_STRING, |
| 25 | + }, |
| 26 | + BillingMode: dynamodb.BillingMode_PAY_PER_REQUEST, |
| 27 | + TableName: aws.String("Username"), |
| 28 | + }) |
| 29 | + |
| 30 | + awscdk.Tags_Of(table).Add(aws.String("Name"), aws.String("Username"),nil) |
| 31 | + |
| 32 | + return stack |
| 33 | +} |
| 34 | + |
| 35 | +func main() { |
| 36 | + app := awscdk.NewApp(nil) |
| 37 | + |
| 38 | + NewDynamodbCdkGoStack(app, "DynamodbCdkGoStack", &DynamodbCdkGoStackProps{ |
| 39 | + awscdk.StackProps{ |
| 40 | + Env: env(), |
| 41 | + }, |
| 42 | + }) |
| 43 | + |
| 44 | + app.Synth(nil) |
| 45 | +} |
| 46 | + |
| 47 | +// env determines the AWS environment (account+region) in which our stack is to |
| 48 | +// be deployed. For more information see: https://docs.aws.amazon.com/cdk/latest/guide/environments.html |
| 49 | +func env() *awscdk.Environment { |
| 50 | + // If unspecified, this stack will be "environment-agnostic". |
| 51 | + // Account/Region-dependent features and context lookups will not work, but a |
| 52 | + // single synthesized template can be deployed anywhere. |
| 53 | + //--------------------------------------------------------------------------- |
| 54 | + return nil |
| 55 | + |
| 56 | + // Uncomment if you know exactly what account and region you want to deploy |
| 57 | + // the stack to. This is the recommendation for production stacks. |
| 58 | + //--------------------------------------------------------------------------- |
| 59 | + // return &awscdk.Environment{ |
| 60 | + // Account: jsii.String("123456789012"), |
| 61 | + // Region: jsii.String("us-east-1"), |
| 62 | + // } |
| 63 | + |
| 64 | + // Uncomment to specialize this stack for the AWS Account and Region that are |
| 65 | + // implied by the current CLI configuration. This is recommended for dev |
| 66 | + // stacks. |
| 67 | + //--------------------------------------------------------------------------- |
| 68 | + // return &awscdk.Environment{ |
| 69 | + // Account: jsii.String(os.Getenv("CDK_DEFAULT_ACCOUNT")), |
| 70 | + // Region: jsii.String(os.Getenv("CDK_DEFAULT_REGION")), |
| 71 | + // } |
| 72 | +} |
0 commit comments