$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”。我尝试了几件事,但对我不起作用
如果有人可以尝试我的脚本并让我知道问题出在哪里
您需要使用多行字符串,例如:
$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。