-
Notifications
You must be signed in to change notification settings - Fork 4k
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
aws-glue-alpha: Creating database uses account id at synthesis time #32720
Comments
@axelson If you deploy using CDK, then the Catalog Id would be properly set using the account ID that created CDK stack. Since you are using CDK to generate CFN template and using it manually to create stack via AWS CLI or CloudFormation console UI, you get the undesirable result. However, I understand your scenario. Reproducible using code below: import * as cdk from 'aws-cdk-lib';
import * as glue from '@aws-cdk/aws-glue-alpha';
export class GlueTestStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new glue.Database(this, `TestGlue-database`, {
databaseName: `TestGlue-nested-database`.replace('-', '_')
});
}
} This synthesizes into below CFN template: Resources:
TestGluedatabase24986573:
Type: AWS::Glue::Database
Properties:
CatalogId: "<<ACCOUNT-ID>>"
DatabaseInput:
Name: TestGlue_nested-database
Metadata:
aws:cdk:path: GlueTestStack/TestGlue-database/Resource
CDKMetadata:
Type: AWS::CDK::Metadata
Properties:
Analytics: v2:deflate64:H4sIAAAAAAAA/zXLTQqDMBBA4bNkn4w/DeiyYE9gD1DGONpoGsVJ6kK8e5Hq6i0eXw5ZcYNNC1xZmXZUzjawPQOaUeLKr95FgqrzDwzYIJOsOl8TT3ExtEut0M1vhFTcT58cPdB5LrdLP7UEAyffrIQ8BS0GtlYt0Qf7Iaj//QENPTP4jwAAAA==
Metadata:
aws:cdk:path: GlueTestStack/CDKMetadata/Default
Parameters:
BootstrapVersion:
Type: AWS::SSM::Parameter::Value<String>
Default: /cdk-bootstrap/hnb659fds/version
Description: Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip] Account ID is set as hardcoded value of the current account for Per AWS::Glue::Connection, The fix could be to use import * as cdk from 'aws-cdk-lib';
import * as glue from '@aws-cdk/aws-glue-alpha';
export class GlueTestStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new glue.Database(this, `TestGlue-database`, {
databaseName: `TestGlue-${cdk.Aws.ACCOUNT_ID}-nested-database`.replace('-', '_')
});
}
} generates below CDN template when synthesized (this uses Resources:
TestGluedatabase24986573:
Type: AWS::Glue::Database
Properties:
CatalogId: "<<ACCOUNT-ID>>"
DatabaseInput:
Name:
Fn::Join:
- ""
- - TestGlue_
- Ref: AWS::AccountId
- -nested-database
Metadata:
aws:cdk:path: GlueTestStack/TestGlue-database/Resource
CDKMetadata:
Type: AWS::CDK::Metadata
Properties:
Analytics: v2:deflate64:H4sIAAAAAAAA/zXLTQqDMBBA4bNkn4w/DeiyYE9gD1DGONpoGsVJ6kK8e5Hq6i0eXw5ZcYNNC1xZmXZUzjawPQOaUeLKr95FgqrzDwzYIJOsOl8TT3ExtEut0M1vhFTcT58cPdB5LrdLP7UEAyffrIQ8BS0GtlYt0Qf7Iaj//QENPTP4jwAAAA==
Metadata:
aws:cdk:path: GlueTestStack/CDKMetadata/Default
Parameters:
BootstrapVersion:
Type: AWS::SSM::Parameter::Value<String>
Default: /cdk-bootstrap/hnb659fds/version
Description: Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip] |
@ashishdhingra Thank you for taking a look! I'm not sure if I fully understand your second code snippet. If I understand correctly that would result in the database name including the correct AWS account id, but the |
@axelson The 2nd snippet just demonstrates for reference purposes that using Aws.AccountId would emit Ref: AWS::AccountId pseudo parameter in synthesized CFN template (Currently, due to issue, it will still use hardcoded account ID in output CFN template). So after CDK team fixes the issue, then if you take the template and deploy it using AWS CLI or CloudFormation UI (as you are doing currently), it should use account ID of account which deploys the stack. |
Ah, I see. Thank you! |
Describe the bug
I am using CDK (via the aws-cdk.aws-glue-alpha python package) to publish a template that users will run. In that template I'm instantiating a
aws_glue_alpha.Database
instance. When I use CDK to synthesize the template the account id ends up hard-coded in the synthesized template. I'm relatively sure that this comes from thecdk.Stack.of(this).account
here:aws-cdk/packages/@aws-cdk/aws-glue-alpha/lib/connection.ts
Line 206 in 2d1e718
Regression Issue
Last Known Working CDK Version
none
Expected Behavior
Instead I expect the catalog to be created under the user that has created the CDK stack (not the user that published the template)
Current Behavior
Since the catalog is created that references the wrong AWS account I get an error like:
I've tested that
Aws.ACCOUNT_ID
should resolve the error by dropping down to the level 1 constructCfnDatabase
. If instantiate that withcatalog_id=aws_cdk.Stack.of(self).account
then I get the error, but if I instantiate it withcatalog_id=Aws.ACCOUNT_ID
then the when I deploy the published stack I get a new catalog which is what I want.Reproduction Steps
Here's the python CDK stack:
It can be used with:
Then, when logged in as a separate account, use the generated template to create a new stack via the CloudFormation UI (or with
aws cloudformation create-stack
and passing in the template)Possible Solution
I think instead that the account for the catalog should be referenced via
Aws.ACCOUNT_ID
Additional Information/Context
No response
CDK CLI Version
2.146.0 (build b368c78) (but I've tested v2.172.0 also)
Framework Version
No response
Node.js Version
v22.12.0
OS
GitHub actions ubuntu-latest (but also reproduced on macOS 15.1.1)
Language
Python
Language Version
Python (3.1.2)
Other information
No response
The text was updated successfully, but these errors were encountered: