swagger - CDK 部署后 CloudFormation 模板未更新
问题描述
我有一个生成的 Swagger json 文件。我有一个读取此文件的 CDK 应用程序,然后执行
const cfnRestApi = this.api.node.defaultChild as apigateway.CfnRestApi;
cfnRestApi.body = JSON.parse(JSON.stringify(swaggerDefinition));
在我查看 Cloud Formation 模板时执行 cdk deploy 后,它包含我的 Swagger 信息。但是,当我对 Swagger json 文件进行更改时,即使 cdk deploy 成功运行,CloudFormation 中的模板也不会更新。我该如何解决这个问题?
解决方案
我会将swaggerDefinition
文件的读取移动bin/myapp.ts
到您的堆栈接口并添加一个额外的参数。像这样的东西:
// ===>>> this is in the bin/myapp.ts
const swaggerDefinition = // read swagger file
new MyAppStack(app, 'MyAppStack', {
swaggerDefinition,
});
// ===>>> now your lib/myapp.ts
export interface MyAppStackProps extends cdk.StackProps {
swaggerDefinition: string; // or whatever type you think it needs
}
export class MyAppStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props: MyAppStackProps) {
super(scope, id, props);
...
// now you can use it freely in cdk code
其背后的原因是,一旦您处于 cdk 构造中,您就不能真正指望承诺的顺序,但是您可以在 bin 端以更可预测的方式做任何您想做的事情。
推荐阅读
- javascript - 我应该添加运行时类型保护吗?
- django - 这两种在 Django 中提供静态文件的方法有什么区别?
- firebase - 在 Firebase 中添加自定义 Oauth2 提供程序
- sql - 从多对多表中添加总计和存在聚合的高效 SQL 查询
- git - 在推送更改时创建重复文件
- c# - 等级增加时如何产生障碍物?
- xcode - '无法启动 iphonesimulator 的模拟器 .. 无法启动模拟器 '
- javascript - 按唯一子元素查找父元素,但单击另一个子元素
- reactjs - 如何在我的浅层测试中定义匹配路由器道具
- python - TensorFlow 中的学习率衰减 - 分段常量函数出错