解析参数'cli-input-json'时出错:当我内联传递json时收到无效的JSON

问题描述 投票:0回答:1



$targetGroupArn = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"


$service = '{
    "cluster": "democluster",
    "serviceName": "demoservice",
    "taskDefinition": "demofamily",
    "loadBalancers": [
        {
            "targetGroupArn": "{{target_Group_Arn}}",
            "containerName": "demodefinition",
            "containerPort": 80
        }
    ],
    "launchType": "FARGATE",
    "schedulingStrategy": "REPLICA",
    "deploymentController": {
        "type": "CODE_DEPLOY"
    },
    "platformVersion": "LATEST",
    "networkConfiguration": {
        "awsvpcConfiguration": {
            "assignPublicIp": "ENABLED",
            "securityGroups": ["sg-xxxxxxxxxx"],
            "subnets": ["subnet-xxxxxxxxxxx", "subnet-xxxxxxxxxxxxx"]
        }
     },
     "desiredCount": 1
   } ' -replace '\{\{target_Group_Arn\}\}', $targetGroupArn;
aws ecs create-service `
   --cli-input-json $service `
   --region ap-southeast-1

Write-Output $DNSName

我尝试通过 powershell 部署 ecs fargate 服务,但收到错误“收到无效的 JSON”。我尝试了几件事,但对我不起作用

如果有人可以尝试我的脚本并让我知道问题出在哪里

amazon-web-services powershell aws-cli aws-fargate
1个回答
0
投票

您需要使用多行字符串,例如:

$service = @"
{
    "cluster": "democluster",
    "serviceName": "demoservice",
    "taskDefinition": "demofamily",
    "loadBalancers": [
        {
            "targetGroupArn": "{{target_Group_Arn}}",
            "containerName": "demodefinition",
            "containerPort": 80
        }
    ],
    "launchType": "FARGATE",
    "schedulingStrategy": "REPLICA",
    "deploymentController": {
        "type": "CODE_DEPLOY"
    },
    "platformVersion": "LATEST",
    "networkConfiguration": {
        "awsvpcConfiguration": {
            "assignPublicIp": "ENABLED",
            "securityGroups": ["sg-xxxxxxxxxx"],
            "subnets": ["subnet-xxxxxxxxxxx", "subnet-xxxxxxxxxxxxx"]
        }
     },
     "desiredCount": 1
}
"@ -replace '\{\{target_Group_Arn\}\}', $targetGroupArn | ConvertFrom-Json

现在变量存储格式化的json。

© www.soinside.com 2019 - 2024. All rights reserved.