-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
CDK aws_apigateway: cannot use imported RestApi with ApiKey because ApiKey references prop only populated on non-imported RestApi #22102
Comments
CDK isn't making any calls to your AWS account unless an import method is specifically configured to do that (usually denoted with the name Usually, if a property on the interface (or proxy) returned by the import method is undefined, then there is a way to define that property through a parameter in Alternatively, in ApiKey we could potentially handle this differently to not require the restApi passed in have the deploymentStage defined, though I'm not sure how we would accomplish this exactly
|
I am marking this issue as p2, which means that we are unable to work on this immediately. We use +1s to help prioritize our work, and are happy to revaluate this issue based on community feedback. You can reach out to the cdk.dev community on Slack to solicit support for reprioritization. Check out our contributing guide if you're interested in contributing yourself - there's a low chance the team will be able to address this soon but we'd be happy to review a PR 🙂 |
@peterwoodworth If this can't be solved soon, then what is your recommended approach for creating an api key for an existing api gw? |
@sempfa you can use the CfnApiKey resource, it's very similar to the ApiKey construct and will create the same resource. Something like this: new CfnApiKey(this, 'ApiKey', {
enabled: true,
name: 'Tenant-key',
stageKeys: [
{
restApiId: 'restApiId',
stageName: 'StageName'
}
]
}); Alternatively you can stay on the L2 level. If you do this you would want to not pass in anything to the const key = new ApiKey(this, 'ApiKey', {
apiKeyName: 'Tenant-key'
});
const cfnKey = key.node.defaultChild as CfnApiKey;
cfnKey.addPropertyOverride('StageKeys', [
{
RestApiId: 'restApiId',
StageName: 'StageName'
}
]); |
…2368) The current implementation of `ApiKey` is a little confusing. It takes a `resources` property which expects a list of `IRestApi`s. An ApiKey is not associated with a RestApi by itself though, it needs to be associated with a specific `Stage` on the RestApi. When you import a RestApi you cannot import it with a `Stage` and even if you could provide an `IStage` I don't think that makes the most sense (you can have multiple stages). Instead, this PR deprecates the `resources` prop and adds a new `stages` prop which expects a list of `IStage`s. To facilitate this I have also done a couple of other things - Added the ability to import a Stage using `Stage.fromStageAttributes()`. - Added an `addApiKey` method to `IStage`. - Added additional error handling if the user does try to create an ApiKey with an imported RestApi. fixes #22102 ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn 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*
|
Describe the bug
When using
RestApi.fromRestApiId
,deploymentStage
property is not populated.this effects other areas, such as creating an API Key to add to the RestApi, ie:
(where
api
is the object created from.fromRestApiId
)returns error "Cannot read property 'stageName' of undefined"
Expected Behavior
deploymentStage
property populated fromRestApi.fromRestApiId
Current Behavior
deploymentStage
undefinedReproduction Steps
use .fromRestApiId to reference existing API:
const api = apigw.RestApi.fromRestApiId(this, "clientApi", 'xxxx123');
create APIKey
Possible Solution
populate
deploymentStage
propertyimplement
.addApiKey
method on object created from.fromRestApiId
Additional Information/Context
Api is created in another stack and is used for a much larger system... the app being created only needs to generate an API Key and a bucket and add them to param store.
CDK CLI Version
2.41.0 (build 6ad48a3)
Framework Version
No response
Node.js Version
v16.16.0
OS
Mac
Language
Typescript
Language Version
3.9.7
Other information
No response
The text was updated successfully, but these errors were encountered: