任務定義中的 containerDefinition 需要作為單個有效 JSON 檔案提供。我正在創建一個應該處理動態資料的通用 ECS 服務。這是代碼:
genericClientService(environment: string, targetGroupArn: Output<string>) {
return new aws.ecs.Service(`${this.domainName}-client-service-${environment}`, {
cluster: this.clientCluster.id,
taskDefinition: new aws.ecs.TaskDefinition(`${this.domainName}-client-${environment}`, {
family: `${this.domainName}-client-${environment}`,
containerDefinitions: JSON.stringify(
clientTemplate(
this.defaultRegion,
this.domainName,
this.taskEnvVars?.filter((object: { ENVIRONMENT: string }) => object.ENVIRONMENT === environment),
this.ecrRepositories
)
),
cpu: "256",
executionRoleArn: taskDefinitionRole.arn,
memory: "512",
networkMode: "awsvpc",
requiresCompatibilities: ["FARGATE"],
}).arn,
desiredCount: 1,
...
需要來自已構建資源this.ecrRepositories的資訊,該資源表示所需的 ECR 存盤庫串列。這里的問題是,假設您要檢索存盤庫 URL 并應用必要的“apply()”方法,它將回傳一個 Output<string>。這通常沒問題,但由于containerDefinitions需要是一個有效的 JSON 檔案,Pulumi 無法處理它,因為 Output<T> 上的 JSON 不受支持;
不支持在 [Output<T>] 上呼叫 [toJSON]。要將輸出的值作為 JSON 值或 JSON 字串,請考慮: 1: o.apply(v => v.toJSON()) 2: o.apply(v => JSON.stringify(v)) 請參閱https ://pulumi.io/help/outputs了解更多詳情。這個函式可能會拋出@pulumi/pulumi 的未來版本。塊參考
由于動態傳遞的變數被包裝在 toJSON 函式回呼中,上述建議的考慮都不起作用。因此,如何傳遞資源資訊并不重要,因為它始終是一個 Output<T>。
有沒有辦法處理這個問題?
uj5u.com熱心網友回復:
假設clientTemplate作業正常并且錯誤發生在您共享的代碼段中,您應該能夠解決它
containerDefinitions: pulumi.all(
clientTemplate(
this.defaultRegion,
this.domainName,
this.taskEnvVars?.filter((object: { ENVIRONMENT: string }) => object.ENVIRONMENT === environment),
this.ecrRepositories
)).apply(JSON.stringify),
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/448551.html
下一篇:如何將外部RESTAPI回應主體從json/string轉換/使用為bean-我正在使用SpringBoot-Maven
