Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

golang cdk: using cli sso profile adds slash in region #17320

Closed
jamesnealcontino opened this issue Nov 4, 2021 · 5 comments
Closed

golang cdk: using cli sso profile adds slash in region #17320

jamesnealcontino opened this issue Nov 4, 2021 · 5 comments
Assignees
Labels
bug This issue is a bug. jsii This issue originates in jsii, or this feature must be implemented in jsii. p1 package/tools Related to AWS CDK Tools or CLI

Comments

@jamesnealcontino
Copy link

What is the problem?

When using a cli sso profile to deploy a Go CDK app, an extra slash is added before the region.

Checking: "~/.aws/config - profile" shows just "region = ap-southeast-2"

the cli returns with "Unable to parse environment specification \"aws:///ap-southeast-2\". Expected format: aws://account/region"

full cli error log received:

panic: "Unable to parse environment specification \"aws:///ap-southeast-2\". Expected format: aws://account/region"

goroutine 1 [running]:
github.com/aws/jsii-runtime-go/runtime.Invoke({0x1296380, 0xc00048a210}, {0x12b3569, 0x5}, {0xc000149ed8, 0x1, 0x1}, {0x1246a40, 0xc00048e6b0})
        /Users/jamesneal/build-your-own-go/pkg/mod/github.com/aws/[email protected]/runtime/runtime.go:214 +0x246
github.com/aws/aws-cdk-go/awscdk.(*jsiiProxy_App).Synth(0x565c0a0, 0x0)
        /Users/jamesneal/build-your-own-go/pkg/mod/github.com/aws/aws-cdk-go/[email protected]/awscdk.go:395 +0x8e
main.main()
        /Users/jamesneal/aws-workshops/cdk-golang-template/cdk-golang-template.go:42 +0x97
exit status 2
Subprocess exited with error 1

Reproduction Steps

aws sso login --profile

cdk init app --language go

return &awscdk.Environment {
	Account: jsii.String(os.Getenv("CDK_DEFAULT_ACCOUNT")),
	Region:  jsii.String(os.Getenv("CDK_DEFAULT_REGION")),
}

cdk deploy --profile

What did you expect to happen?

Expected cdk to deploy using the region within the chosen cli profile

What actually happened?

an extra slash is getting placed in front of the region

CDK CLI Version

1.130.0

Framework Version

No response

Node.js Version

14.17.6

OS

macOS Big Sur (11.6)

Language

Go

Language Version

go 1.17.2 (darwin/amd64)

Other information

Looks like such a simple bug. Apologies. Have intentions of being able to fix these myself at some point. Wanted to kick it off by getting involved in any way possible.

@jamesnealcontino jamesnealcontino added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 4, 2021
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Nov 4, 2021
@peterwoodworth peterwoodworth added jsii This issue originates in jsii, or this feature must be implemented in jsii. p1 and removed needs-triage This issue or PR still needs to be triaged. labels Nov 4, 2021
@peterwoodworth
Copy link
Contributor

@MrArnoldPalmer could you take a look at this?

@MrArnoldPalmer
Copy link
Contributor

@jamesnealcontino Account: jsii.String(os.Getenv("CDK_DEFAULT_ACCOUNT")), if CDK_DEFAULT_ACCOUNT is not set this returns an empty string. So it is doing aws://account/region with account being "" resulting in an incorrect format. If you aren't explicitly passing an account, remove that line from your code so that Account is correctly nil and not empty string.

If an account is defined via the profile and CDK_DEFAULT_ACCOUNT is not set this is a bug with the CLI I believe. But it would break across all languages and we likely would have more reports.

if you do cdk --profile myProfileName --verbose MyStack this should output what account/region it is resolving. You can paste that output here but make sure to redact any sensitive information.

@rix0rrr are you familiar with any related problems in the CLI?

@jamesnealcontino
Copy link
Author

Both "CDK_DEFAULT_ACCOUNT" and "CDK_DEFAULT_REGION" are being set through aws sso.

I actually can't run cdk synth due to getting the same "Unable to parse environment specification \"aws:///ap-southeast-2\". Expected format: aws://account/region"

It is resolving \"aws:///ap-southeast-2\" just it has an extra slash in it. Even though that slash is no where in the configs.

Is there an order in which the cdk will pull that region from? I'm only aware of ~/.aws/config which just shows ap-southeast-2

@MrArnoldPalmer
Copy link
Contributor

Turns out this is because the cdk cli doesn't currently support named profiles via sso #5455

Gonna close this in favor of that issue.

@github-actions
Copy link

⚠️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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. jsii This issue originates in jsii, or this feature must be implemented in jsii. p1 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

4 participants