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

[aws-dynamodb] when setting PhysicalName.GENERATE_IF_NEEDED to tableName, throwing error Invalid physical name passed to CloudFormation. Use "this.physicalName" instead #9374

Closed
flyingImer opened this issue Jul 31, 2020 · 12 comments · Fixed by #9377 or #19638
Assignees
Labels
@aws-cdk/aws-dynamodb Related to Amazon DynamoDB bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@flyingImer
Copy link
Contributor

Hi team, I'm trying to do a cross-env reference on a ddb table. After I specify the tableName to PhysicalName.GENERATE_IF_NEEDED, synthesizing process breaks.

The error message says:

Error: Resolution error: Invalid physical name passed to CloudFormation. Use "this.physicalName" instead.

I suspect this is a bug, as my experiment on a cross-env referenced IAM role works just fine with PhysicalName.GENERATE_IF_NEEDED (not included in the example below)

And I think this error message is confusing. I have no idea what to do with this message. Any context how should I interpret it?

Reproduction Steps

here is an example I used: https://github.com/flyingImer/cdk-mkii

cdk synth breaks even without SomeStack referencing to the ddb table defined in CdkMkiiStack

Error Log

Error: Resolution error: Invalid physical name passed to CloudFormation. Use "this.physicalName" instead.
    at GeneratedWhenNeededMarker.resolve (/Users/Can/ws-local/github/cdk-mkii/node_modules/@aws-cdk/core/lib/private/physical-name-generator.ts:89:11)
    at DefaultTokenResolver.resolveToken (/Users/Can/ws-local/github/cdk-mkii/node_modules/@aws-cdk/core/lib/resolvable.ts:134:24)
    at resolve (/Users/Can/ws-local/github/cdk-mkii/node_modules/@aws-cdk/core/lib/private/resolve.ts:133:29)
    at Object.resolve [as mapToken] (/Users/Can/ws-local/github/cdk-mkii/node_modules/@aws-cdk/core/lib/private/resolve.ts:49:32)
    at TokenizedStringFragments.mapTokens (/Users/Can/ws-local/github/cdk-mkii/node_modules/@aws-cdk/core/lib/string-fragments.ts:71:33)
    at DefaultTokenResolver.resolveString (/Users/Can/ws-local/github/cdk-mkii/node_modules/@aws-cdk/core/lib/resolvable.ts:155:22)
    at resolve (/Users/Can/ws-local/github/cdk-mkii/node_modules/@aws-cdk/core/lib/private/resolve.ts:91:31)
    at Object.resolve (/Users/Can/ws-local/github/cdk-mkii/node_modules/@aws-cdk/core/lib/private/resolve.ts:49:32)
    at Object.resolve (/Users/Can/ws-local/github/cdk-mkii/node_modules/@aws-cdk/core/lib/private/resolve.ts:155:39)
    at CdkMkiiStack.resolve (/Users/Can/ws-local/github/cdk-mkii/node_modules/@aws-cdk/core/lib/stack.ts:363:12)

Environment

  • CLI Version : 1.55.0 (build 48ccf09)
  • Framework Version: 1.55.0
  • Node.js Version: v12.16.2
  • OS : macOS 10.15.6
  • Language (Version): TypeScript

Other


This is 🐛 Bug Report

@flyingImer flyingImer added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 31, 2020
@github-actions github-actions bot added the @aws-cdk/aws-dynamodb Related to Amazon DynamoDB label Jul 31, 2020
@skinny85
Copy link
Contributor

Hey @flyingImer ,

thanks for opening the issue. Would you mind showing a particular snippet that causes this? It's hard to find it in an entire GutHub project. That will help us diagnose immensely. Thanks!

@flyingImer
Copy link
Contributor Author

@skinny85
Copy link
Contributor

@flyingImer thanks! I confirm I can reproduce it on a minimal example like this:

        new ddb.Table(this, 'SomeTable', {
            partitionKey: {
                name: 'someKey',
                type: ddb.AttributeType.STRING
            },
            tableName: cdk.PhysicalName.GENERATE_IF_NEEDED // even without cross-env reference, this line still throws the error
        });

Thanks for reporting - this definitely looks like a bug, either in the DynamoDB library, or in the core physical name resolution.

@skinny85
Copy link
Contributor

Yep, I think it's in the DynamoDB library. I should have a fix out soon.

@skinny85 skinny85 assigned skinny85 and unassigned RomainMuller Jul 31, 2020
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Jul 31, 2020
@mergify mergify bot closed this as completed in #9377 Aug 2, 2020
mergify bot pushed a commit that referenced this issue Aug 2, 2020
…le name (#9377)

Fixes #9374

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
curtiseppel pushed a commit to curtiseppel/aws-cdk that referenced this issue Aug 11, 2020
…le name (aws#9377)

Fixes aws#9374

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@ChristianTrummer99
Copy link

ChristianTrummer99 commented Mar 23, 2022

This seems to still be an issue, except for API Gateway:

        api = apigateway.LambdaRestApi(self, 'TransactionServicesAPIs',
            deploy_options=apigateway.StageOptions(
                stage_name='test',
            ),
            handler=fn,
            proxy=False,
            rest_api_name=PhysicalName.GENERATE_IF_NEEDED,
        )
-> jsii.errors.JSIIError: Resolution error: Resolution error: Resolution error:
Invalid physical name passed to CloudFormation. Use "this.physicalName" instead...

@skinny85
Copy link
Contributor

Confirmed I was able to reproduce the issue @ChristianTrummer99 (in TypeScript, the language doesn't actually matters here as it turns out).

Working on a fix.

@skinny85
Copy link
Contributor

Fix: #19638.

mergify bot pushed a commit that referenced this issue Mar 31, 2022
… in LambdaRestApi (#19638)

Fixes #9374

----

### All Submissions:

* [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
StevePotter pushed a commit to StevePotter/aws-cdk that referenced this issue Apr 27, 2022
… in LambdaRestApi (aws#19638)

Fixes aws#9374

----

### All Submissions:

* [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@isaiahvita
Copy link

hello,
I am seeing a similar issue for S3 buckets. is this still an issue for S3?

        this.pluginBucket = new Bucket(this, "DistributionBucket", {
            bucketName: PhysicalName.GENERATE_IF_NEEDED,
            blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
            objectOwnership: ObjectOwnership.BUCKET_OWNER_ENFORCED,
            enforceSSL: true,
            serverAccessLogsBucket: pluginBucketServerAccessLogsBucket,
            versioned: true
        })

results in:

Error: Resolution error: Resolution error: Resolution error: Invalid physical name passed to CloudFormation. Use "this.physicalName" instead...
    at GeneratedWhenNeededMarker.resolve (/home/ubuntu/gorgon-nuke/cdk/pipeline/node_modules/aws-cdk-lib/core/lib/private/physical-name-generator.js:1:2022)
    at RememberingTokenResolver.resolveToken (/home/ubuntu/gorgon-nuke/cdk/pipeline/node_modules/aws-cdk-lib/core/lib/resolvable.js:1:1238)
    at RememberingTokenResolver.resolveToken (/home/ubuntu/gorgon-nuke/cdk/pipeline/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:4058)
    at resolve (/home/ubuntu/gorgon-nuke/cdk/pipeline/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:2661)
    at Object.resolve [as mapToken] (/home/ubuntu/gorgon-nuke/cdk/pipeline/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:1121)
    at TokenizedStringFragments.mapTokens (/home/ubuntu/gorgon-nuke/cdk/pipeline/node_modules/aws-cdk-lib/core/lib/string-fragments.js:1:1365)
    at RememberingTokenResolver.resolveString (/home/ubuntu/gorgon-nuke/cdk/pipeline/node_modules/aws-cdk-lib/core/lib/resolvable.js:4:358)
    at RememberingTokenResolver.resolveString (/home/ubuntu/gorgon-nuke/cdk/pipeline/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:4134)
    at resolve (/home/ubuntu/gorgon-nuke/cdk/pipeline/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:2045)
    at Object.resolve (/home/ubuntu/gorgon-nuke/cdk/pipeline/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:1121)

@skinny85
Copy link
Contributor

@isaiahvita are you 100% sure the problem is with this code? Not somewhere else?

@renschler
Copy link

renschler commented Feb 4, 2023

I'm seeing this error for SecretsManager keys

    const sengridAPIKey = new secretsmanager.Secret(
      this,
      `sengridAPIKey-${deployEnv}`,
      {
        secretName: PhysicalName.GENERATE_IF_NEEDED,
      }
    );
Error: Resolution error: Resolution error: Resolution error: Resolution error: Invalid physical name passed to CloudFormation. Use "this.physicalName" instead..
Object creation stack:

seems like this was a similar issue closed to inactivity: #16167

I did get things to work for s3 buckets and dynamodb tables, so it's just Secrets which still have this issue as far as I know.

@skinny85
Copy link
Contributor

skinny85 commented Feb 5, 2023

@renschler can you show how are you using sengridAPIKey?

@joshbalfour
Copy link

joshbalfour commented Jul 3, 2023

I'm also seeing this when referencing secret.secretName, secret.secretArn works fine though.

edit:
A workaround is to grab the name from the arn:

import { Arn, ArnFormat } from 'aws-cdk-lib'

const { resourceName } = Arn.split(secret.secretArn, ArnFormat.COLON_RESOURCE_NAME)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-dynamodb Related to Amazon DynamoDB bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
7 participants