简体   繁体   English

AWS CDK 中 app.synth() 的用途是什么?

[英]What is the purpose of app.synth() in AWS CDK?

What is the purpose of the app.synth() line in AWS CDK applications? AWS CDK 应用程序中app.synth()行的用途是什么? For example it can be seen here on line 29: https://github.com/aws-samples/aws-cdk-examples/blob/master/typescript/ecs/fargate-application-load-balanced-service/index.ts例如,它可以在第 29 行看到: https ://github.com/aws-samples/aws-cdk-examples/blob/master/typescript/ecs/fargate-application-load-balanced-service/index.ts

I have looked at the CDK docs but I cannot find what the actual purpose of that function is.我查看了 CDK 文档,但找不到该函数的实际用途。 As I understand it, the app is automatically synthesized upon cdk deploy or cdk synth .据我了解,该应用程序是在cdk deploycdk synth时自动合成的。 I also took the example shown in repo linked above, commented out the app.synth() line, deployed it, and it seemed to work as expected.我还采用了上面链接的 repo 中显示的示例,注释掉了app.synth()行,部署了它,它似乎按预期工作。 Therefore I'm wondering if I'm missing something when it comes to the purpose of app.synth()因此,我想知道在 app.synth() 的目的方面我是否遗漏了什么

cdk synth only constructs your CloudFormation template . cdk synth仅构建您的 CloudFormation 模板 It does not deploy (create actual resources) it to AWS.它不会将其部署(创建实际资源)到 AWS。 You can take the template constructed, deploy it manually in CFN console, edit or inspect.您可以使用构建的模板,在 CFN 控制台中手动部署,编辑或检查。

cdk deploy is going to construct the template and deploy it to AWS as well. cdk deploy将构建模板并将其部署到 AWS

People use synth with deploy because it is a good practice :人们将synthdeploy一起deploy因为这是一个很好的做法

It is optional (though good practice ) to synthesize before deploying.在部署之前进行综合是可选的(尽管很好的做法)。 The AWS CDK synthesizes your stack before each deployment. AWS CDK 在每次部署之前综合您的堆栈。

I know it's been a while since this question was asked, but I was curious and looked into it myself, so I'll share it with you.我知道这个问题被问到已经有一段时间了,但是我很好奇并自己研究了它,所以我会与你分享。

The App class has an option called autoSynth which is set to true by default, so even if you omit app.synth() in your code, it will be executed automatically. App类有一个名为autoSynth的选项,默认设置为true ,因此即使您在代码中省略app.synth() ,它也会自动执行。 https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.AppProps.html#autosynth https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.AppProps.html#autosynth

As mentioned in the documentation, this feature may not work in some languages, so it seems to be explicitly specified in many sample codes.如文档中所述,此功能可能不适用于某些语言,因此似乎在许多示例代码中都明确指定了它。

According to the documentation, it is OK to run app.synth() multiple times.根据文档,多次运行app.synth()是可以的。 https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.App.html#synthoptions https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.App.html#synthoptions

autoSynth works fine in Node.js. autoSynth在 Node.js 中运行良好。 It is implemented in Node.js using process.once("beforeExit", listener) .它是在 Node.js 中使用process.once("beforeExit", listener)实现的。 https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/core/lib/app.ts#L127-L132 https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/core/lib/app.ts#L127-L132

I started this investigation because when I ran CDK in Deno, I had to explicitly run app.synth() to generate the CDK assembly.我开始这项调查是因为当我在 Deno 中运行 CDK 时,我必须显式运行app.synth()来生成 CDK 程序集。 As a result of this investigation, I found out that this is because the Node compatibility layer in Deno does not currently support "beforeExit" events.通过这次调查,我发现这是因为 Deno 中的 Node 兼容层目前不支持“beforeExit”事件。 https://github.com/denoland/deno_std/blob/113435ada1948b90188586f022d55745c6d2d19b/node/process.ts#L51-L52 https://github.com/denoland/deno_std/blob/113435ada1948b90188586f022d55745c6d2d19b/node/process.ts#L51-L52

As per this experience, it is better to explicitly call app.synth() as recommended.根据此经验,最好按照建议显式调用app.synth()

目的是什么<div classname="“App”">在反应 class 渲染 function?</div><div id="text_translate"><p> 我是 React 新手,到目前为止,我知道 React jsx 中的 className 可以是对在导入的 css 文件中定义的 html class 的引用。 就像下面示例中的className="warning"一样,它使文本显示为红色,而不是默认的黑色。</p><p> 但我也看到,在许多教程示例中,像&lt;div className="App"&gt;这样的元素出现在 render() function 的顶部。 这通常不会引用导入的 css 文件中的任何内容,但即使示例中根本没有导入的 css 文件,它也经常存在。</p><p> 事实上,我发现如果我只用&lt;div&gt;替换它,该示例的呈现方式与以前完全相同。 那么像&lt;div className="App"&gt;这样的元素有什么作用,它们有什么用呢?</p><p> 应用程序.js</p><pre> import React, { Component } from 'react'; import './App.css'; class App extends Component { render() { return ( &lt;div className="App"&gt; &lt;h1 className="warning"&gt;Wakeup World;&lt;/h1&gt; &lt;/div&gt; ) } } export default App;</pre><p> 应用程序.css</p><pre> .warning { color: red }</pre></div> - What's the purpose of <div className=“App”> in a React class render function?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 aws-cdk yarn synth -o /tmp/artifacts 返回错误 ENOENT:没有这样的文件或目录,打开 '/tmp/artifacts/manifest.json' - aws-cdk yarn synth -o /tmp/artifacts returning error ENOENT: no such file or directory, open '/tmp/artifacts/manifest.json' 在 Typescript 中的 AWS CDK 应用程序中读取道具 - Reading props in a AWS CDK app in Typescript @aws-cdk/pipelines 和 @aws-cdk/aws-codepipeline 有什么区别? - What is the difference between @aws-cdk/pipelines and @aws-cdk/aws-codepipeline? 这个简单的FM合成器设计出了什么问题? - What's wrong with this simple FM synth design? AWS CDK 用户池授权者 - AWS CDK user pool authorizer Vite.js 应用程序中“main.js”文件的用途是什么? - What is the purpose of the 'main.js' file in a Vite.js app? 发布您的Alexa技能时,APP_ID的目的是什么 - In publishing your alexa skill what is the purpose of APP_ID Laravel 5.3中新的app.js的目的是什么? - What is the purpose of the new app.js in Laravel 5.3? 目的是什么<div classname="“App”">在反应 class 渲染 function?</div><div id="text_translate"><p> 我是 React 新手,到目前为止,我知道 React jsx 中的 className 可以是对在导入的 css 文件中定义的 html class 的引用。 就像下面示例中的className="warning"一样,它使文本显示为红色,而不是默认的黑色。</p><p> 但我也看到,在许多教程示例中,像&lt;div className="App"&gt;这样的元素出现在 render() function 的顶部。 这通常不会引用导入的 css 文件中的任何内容,但即使示例中根本没有导入的 css 文件,它也经常存在。</p><p> 事实上,我发现如果我只用&lt;div&gt;替换它,该示例的呈现方式与以前完全相同。 那么像&lt;div className="App"&gt;这样的元素有什么作用,它们有什么用呢?</p><p> 应用程序.js</p><pre> import React, { Component } from 'react'; import './App.css'; class App extends Component { render() { return ( &lt;div className="App"&gt; &lt;h1 className="warning"&gt;Wakeup World;&lt;/h1&gt; &lt;/div&gt; ) } } export default App;</pre><p> 应用程序.css</p><pre> .warning { color: red }</pre></div> - What's the purpose of <div className=“App”> in a React class render function? 在React Native Firebase中调用firebase.app()的目的是什么? - What is the purpose of calling firebase.app() in react native firebase?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM