-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
(apigateway): support deployment salting for imported RestApi #12417
Comments
Unfortunately, this isn't easy to implement since import APIs are intended to create API Gateway resources that are unaware of others. This is how we are able to split off these resources into different stacks and not cause cyclic dependencies. Manually salting the deployment (as described in your workaround) is the best option available. Moving this to a feature request. |
|
Per #13383, if latestDeployment were to be set when calling RestApi.fromRestApiAttributes() this issue should be resolved without even needing to create a Deployment resource manually within the stack. |
Hi @tmclaugh - I'm keen to explore your statement here. The Let's take the simple case where a How do you propose your approach tackle this case? |
Any news on this topic? |
Hey Team, I am using the below code which is working for me. const deployment = new Deployment(this, `deployment-${new Date().toISOString()}`, { api: apiGateway });
// @ts-ignore
deployment.resource.stageName = ENV!;
const logicalId = Date.now().toString();// salted id
const cfnDeployment = deployment.node.defaultChild as CfnDeployment;
cfnDeployment.overrideLogicalId(logicalId);
I am doing deployment two times to make it work. This will be like npx aws-cdk synth
npx aws-cdk deploy --require-approval never
npx aws-cdk deploy --require-approval never |
Just ran into this issue, deploying two times does the trick but doesn't seem ideal to me, neither creating a separate Stage when the underlying issue seems to be related to the interface of the imported RestApi being IRestApi. |
+1 to this. It's the only reason that is preventing us from using AWS CDK for projects at work. Creating a new deployment every time by changing the deployment id seems overkill. |
I don't see how we can solve this without doing hacks. The core problem, as @nija-at explained, is that, by importing a Rest API, you don't have access to its Deployment. I'm closing this issue for now, but if someone has an idea for a solution, please share it with us, either by creating a new ticket or submitting a PR, and we may come back to this. |
|
I overcome this by overwriting the _latestDeployment variable on the RestApi, this needs to be done prior to adding any methods. //...
/**
* Initialise the rest api
*/
public readonly restApi = new RestApi(this, 'api', {
restApiName: `falcon-${this.props.envName}-poshub`,
deploy: false,
defaultCorsPreflightOptions,
})
/**
* Documentation Version
*/
public readonly version = new CfnDocumentationVersion(this, 'version', {
documentationVersion: '1.1.44',
restApiId: this.restApi.restApiId,
description: 'this is a test of documentation',
})
/**
* Rest API Deployment
*/
public readonly deployment = new Deployment(this, 'deployment', {
api: this.restApi,
description: `Deployment: ${this.props.envName}/${this.version.documentationVersion}`,
})
// This patch needs to be applied prior to mounting the ApiMethods construct
// This being present on the restApi allows for all methods to be bound to the deployment
protected forceLatestDeploymentOverride = (this.restApi['_latestDeployment'] =
this.deployment)
//... This may work for imported reset api's as well but I haven't tested, this resolves two issues with my setup:
Hope this helps |
If the RestApi is define by RestApi.fromRestApiAttributes(), any deployment will not add salt to the deployment resource.
Reproduction Steps
This is my code.
"taotest123deploymentC642C343" is the resource name in the Cloudformation template.
What did you expect to happen?
add salt to the resource name
What actually happened?
no salt was added to the resource name
Environment
Other
WORKAROUND: Just in case anyone ran into the same problem, you can force a deployment by manually adding salt to deployment id. in above example, 123_deployment is my deployment id, you can change the id 1234_deployment to force new deployment to deploy.
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: