|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + cdk "github.com/aws/aws-cdk-go/awscdk/v2" |
| 5 | + s3 "github.com/aws/aws-cdk-go/awscdk/v2/awss3" |
| 6 | + "github.com/aws/constructs-go/constructs/v10" |
| 7 | + "github.com/aws/jsii-runtime-go" |
| 8 | +) |
| 9 | + |
| 10 | +type GoodGoStackProps struct { |
| 11 | + cdk.StackProps |
| 12 | +} |
| 13 | + |
| 14 | +/// AWS CloudFormation Sample Template S3_Website_Bucket_With_Retain_On_Delete: Sample template showing how to create a publicly accessible S3 bucket configured for website access with a deletion policy of retain on delete. |
| 15 | +type GoodGoStack struct { |
| 16 | + cdk.Stack |
| 17 | + /// URL for website hosted on S3 |
| 18 | + WebsiteUrl interface{} // TODO: fix to appropriate type |
| 19 | + /// Name of S3 bucket to hold website content |
| 20 | + S3BucketSecureUrl interface{} // TODO: fix to appropriate type |
| 21 | +} |
| 22 | + |
| 23 | +func NewGoodGoStack(scope constructs.Construct, id string, props GoodGoStackProps) *GoodGoStack { |
| 24 | + stack := cdk.NewStack(scope, &id, &props.StackProps) |
| 25 | + |
| 26 | + s3Bucket := s3.NewCfnBucket( |
| 27 | + stack, |
| 28 | + jsii.String("S3Bucket"), |
| 29 | + &s3.CfnBucketProps{ |
| 30 | + AccessControl: jsii.String("PublicRead"), |
| 31 | + WebsiteConfiguration: &WebsiteConfiguration/* FIXME */{ |
| 32 | + IndexDocument: jsii.String("index.html"), |
| 33 | + ErrorDocument: jsii.String("error.html"), |
| 34 | + }, |
| 35 | + }, |
| 36 | + ) |
| 37 | + |
| 38 | + return &GoodGoStack{ |
| 39 | + Stack: stack, |
| 40 | + WebsiteUrl: s3Bucket.AttrWebsiteUrl(), |
| 41 | + S3BucketSecureUrl: cdk.Fn_Join(jsii.String(""), &[]*string{ |
| 42 | + jsii.String("https://"), |
| 43 | + s3Bucket.AttrDomainName(), |
| 44 | + }), |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +func main() { |
| 49 | + defer jsii.Close() |
| 50 | + |
| 51 | + app := awscdk.NewApp(nil) |
| 52 | + |
| 53 | + NewGoodGoStack(app, "GoodGo", &GoodGoStackProps{ |
| 54 | + awscdk.StackProps{ |
| 55 | + Env: env(), |
| 56 | + }, |
| 57 | + }) |
| 58 | + |
| 59 | + app.Synth(nil) |
| 60 | +} |
| 61 | + |
| 62 | +// env determines the AWS environment (account+region) in which our stack is to |
| 63 | +// be deployed. For more information see: https://docs.aws.amazon.com/cdk/latest/guide/environments.html |
| 64 | +func env() *awscdk.Environment { |
| 65 | + // If unspecified, this stack will be "environment-agnostic". |
| 66 | + // Account/Region-dependent features and context lookups will not work, but a |
| 67 | + // single synthesized template can be deployed anywhere. |
| 68 | + //--------------------------------------------------------------------------- |
| 69 | + return nil |
| 70 | + |
| 71 | + // Uncomment if you know exactly what account and region you want to deploy |
| 72 | + // the stack to. This is the recommendation for production stacks. |
| 73 | + //--------------------------------------------------------------------------- |
| 74 | + // return &awscdk.Environment{ |
| 75 | + // Account: jsii.String("123456789012"), |
| 76 | + // Region: jsii.String("us-east-1"), |
| 77 | + // } |
| 78 | + |
| 79 | + // Uncomment to specialize this stack for the AWS Account and Region that are |
| 80 | + // implied by the current CLI configuration. This is recommended for dev |
| 81 | + // stacks. |
| 82 | + //--------------------------------------------------------------------------- |
| 83 | + // return &awscdk.Environment{ |
| 84 | + // Account: jsii.String(os.Getenv("CDK_DEFAULT_ACCOUNT")), |
| 85 | + // Region: jsii.String(os.Getenv("CDK_DEFAULT_REGION")), |
| 86 | + // } |
| 87 | +} |
0 commit comments