2016-03-22 111 views
0

林創建ELB和應用堆棧...我需要通過子網ELB和應用堆棧的列表...通列表嵌套堆棧AWS

和主JSON有下面的代碼...

"Mappings":{ 
     "params":{ 

       "Subnets": { 
        "dev":[ 
       "subnet-1」, 
       "subnet-2」 
       ], 
        "test":[ 
       "subnet-3」, 
       "subnet-4」, 
       "subnet-5」, 
       "subnet-6」 
       ], 

      "prod":[ 
       "subnet-7」, 
       "subnet-8」, 
       "subnet-9」 
       ] 
       } 
     } 
     }, 
"Parameters":{ 
    "Environment":{ 
     "AllowedValues":[ 
     "prod", 
     "preprod", 
     "dev" 
     ], 
     "Default":"prod", 
     "Description":"What environment type is it (prod, preprod, test, dev)?", 
     "Type":"String" 
    } 
}, 
     Resources:{ 
     "ELBStack": { 
       "Type": "AWS::CloudFormation::Stack", 
       "Properties": { 
       "TemplateURL": { 
        "Fn::Join":[ 
        "", 
        [ 
         "https://s3.amazonaws.com/", 
         "myS3bucket", 
         "/ELB.json" 
        ] 
        ] 
       }, 
       "Parameters": { 
        "Environment":{"Ref":"Environment"}, 

        "ELBSHORTNAME":{"Ref":"ELBSHORTNAME"}, 
        "Subnets":{"Fn::FindInMap":[ 
            "params", 
            "Subnets", 
            { 
            "Ref":"Environment" 
            } 
           ]}, 
        "S3Bucket":{"Ref":"S3Bucket"}, 

       }, 
       "TimeoutInMinutes": "60" 
       } 
     } 

現在,當我使用lambda或cloudformation運行此JSON我得到下面的錯誤下cloudformation活動標籤....沒有很好地形成

CREATE_FAILED AWS::CloudFormation::Stack ELBStack Value of property Parameters must be an object with String (or simple type) properties 

using below lambda 


import boto3 
import time 

date = time.strftime("%Y%m%d") 
time = time.strftime("%H%M%S") 
stackname = 'FulfillSNSELB' 
client = boto3.client('cloudformation') 
response = client.create_stack(
    StackName= (stackname + '-' + date + '-' + time), 
    TemplateURL='https://s3.amazonaws.com/****/**/myapp.json', 
    Parameters=[ 
     { 
      'ParameterKey': 'Environment', 
      'ParameterValue': 'dev', 
      'UsePreviousValue': False 
     }] 
) 

def lambda_handler(event, context): 
    return(response) 

回答

1

你的JSON。通過aws cloudformation validate-template(甚至jsonlint.com)運行你的JSON很快暴露出一些基本的語法錯誤:

  1. Resources:{要求的關鍵,用引號引起來:"Resources": {
  2. 一些你的引號是無效的「智能引號」 "subnet-1」,需要與標準的ASCII引號替換爲:"subnet-1",
  3. (這是一個你的錯誤消息指)的"Properties"對象在「ELBStack」資源"S3Object: {"Ref: "S3Bucket"},"有其最後一個元素之後尾隨逗號需要被刪除:"S3Object: {"Ref: "S3Bucket"}"