aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.65k stars 3.91k forks source link

aws-timestream: Database name is <nil> after created when the name is generated automatically #20994

Closed monemo12 closed 2 years ago

monemo12 commented 2 years ago

Describe the bug

When I create an AWS Timestream database w/o name, it can be created successfully. After that, when I try to use the database name (timestream.CfnDatabase.DatabaseName()) somewhere else in program I got the error. However, when I specify the name of database, it will be fine.

Expected Behavior

When I create an AWS Timestream database w/o name, it should be created successfully and the reference of database name shouldn't be

Current Behavior

Output:

2022/07/05 14:50:35 | base.createTsDatabase
2022/07/05 14:50:35 | base.createTsDatabase: dbName=<nil>
panic: Field *string.Value is required, but has nil value

goroutine 1 [running]:
github.com/aws/jsii-runtime-go/internal/kernel.(*Client).CastPtrToRef(0xad97e0?, {0xafd3c0?, 0xc0000888d0?, 
0x48478a?})
        /home/ubuntu/share/Project/iot-demo/vendor/github.com/aws/jsii-runtime-go/internal/kernel/conversions.go:184 +0xb34
github.com/aws/jsii-runtime-go/runtime.convertArguments({0xc00010fd10, 0x3, 0xb96060?})
        /home/ubuntu/share/Project/iot-demo/vendor/github.com/aws/jsii-runtime-go/runtime/runtime.go:365 +0x111
github.com/aws/jsii-runtime-go/runtime.Create({0xc9de74, 0x15}, {0xc00010fd10, 0x3, 0x3}, {0xc2b180, 0xc0001fcd60})
        /home/ubuntu/share/Project/iot-demo/vendor/github.com/aws/jsii-runtime-go/runtime/runtime.go:180 +0x7fa
github.com/aws/aws-cdk-go/awscdk/v2.NewCfnOutput({0x7f61f1a43898?, 0xc00000e810}, 0xc0001fcd30, 0xc0000888d0)
        /home/ubuntu/share/Project/iot-demo/vendor/github.com/aws/aws-cdk-go/awscdk/v2/awscdk.go:8543 +0xeb 
iot-demo/pkg/infra/base.createTsDatabase()
        /home/ubuntu/share/Project/iot-demo/pkg/infra/base/base.go:78 +0x2f2
iot-demo/pkg/infra/base.NewBaseStack({0x7f61f1a43898?, 0xc00000e810}, {0xc9033d, 0x9}, 0xc000068400)        
        /home/ubuntu/share/Project/iot-demo/pkg/infra/base/base.go:41 +0x13c
iot-demo/pkg/infra/core.CoreStack({0x7f61f1a42030, 0xc0001a5c00}, {0xc903a0, 0x9}, 0xc0003ad590)
        /home/ubuntu/share/Project/iot-demo/pkg/infra/core/core.go:30 +0x2fa
main.main()
        /home/ubuntu/share/Project/iot-demo/cmd/main.go:29 +0x212
exit status 2

Reproduction Steps

Source:


<Ignore...>

    log.Println("| base.createTsDatabase")

    db := timestream.NewCfnDatabase(scp, jsii.String("BaseTimestream"), &timestream.CfnDatabaseProps{
                // DatabaseName: jsii.String("BaseTimestream"), // It will be fine if I uncomment this
        Tags: &[]*awscdk.CfnTag{
            {Key: jsii.String("env"), Value: &props.Env},
            {Key: jsii.String("project"), Value: &props.Project},
        },
    })

    log.Printf("| base.createTsDatabase: dbName=%v\n", db.DatabaseName())

    awscdk.NewCfnOutput(scp, jsii.String("BaseTimestreamDbName"), &awscdk.CfnOutputProps{
        Value: db.DatabaseName(),
    })

<Ignore...>

Then run cdk synth or cdk deploy

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.29.1 (build c42e961)

Framework Version

No response

Node.js Version

v14.19.3

OS

linux

Language

Go

Language Version

go1.18.3 linux/amd64

Other information

No response

kaizencc commented 2 years ago

This is expected behavior. If you don't supply a databaseName, then cloudformation will generate one for you. You won't have that name at synth time, so the value of databaseName at synth time is null. Unfortunately you won't be able to reference the database name elsewhere in your CDK app since it doesn't exist yet :).

github-actions[bot] commented 2 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.