1

I am new to nested stack and i am trying to pass input parameters from parent to child template. My parent stack looks like below:

AWSTemplateFormatVersion: "2010-09-09"
Transform: 'AWS::Serverless-2016-10-31'
Description: "ParentStack with all child stack"

Parameters:
  AccountName:
    Description: Please Enter valid Account Name.
    Type: "CommaDelimitedList"
    Default: "citi"

  Region:
    Description: Enter Region
    Type: "CommaDelimitedList"
    Default: "us-east-2"



  S3BucketName:
    Type: "CommaDelimitedList"
    Default: ""

  S3KeyName:
    Type: "CommaDelimitedList"
    Default: "Test-LambdaFunction.zip"

Resources:
  LambdaStack1:
    Type: "AWS::CloudFormation::Stack"
    Properties:
      Parameters:
        TemplateURL: https://test272t3.s3.us-east-2.amazonaws.com/CFTemplates/lambda.yaml
        CodeUri:
          Bucket: Fn:Join [ ' ', [!Ref S3BucketName] ]
          Key: Fn::Join [ ' ', [!Ref S3KeyName] ]

 S3Stack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: https://test272t3.s3.us-east-2.amazonaws.com/CFTemplates/s3child.yaml
      Parameters:
        BucketName: <<not sure how !sub can be paased in parent stack>>
        AccessControl: PublicReadWrite
        VersioningConfiguration:
          Status: Suspended


And part of child template is as follows:

Parameters:
  AccountName:
    Description: Please Enter valid Account Name.
    Type: String
    Default: citi
  Region:
    Description: Enter Region
    Type: String
    Default: us-east-2

  S3BucketName:
    Type: "String"
    Default: ""

  S3KeyName:
    Type: "String"
    Default: "MeghFlow-DBConnMgmt-Lambda-DBConnMgmtFunction.zip"

testLambda:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: 
        Bucket: !Ref S3BucketName
        Key: !Ref S3KeyName
      Handler: com.testff.testinghand.dbconnmgmt.lambda.testLambda::handleRequest
      Runtime: java8
      MemorySize: 1024
      Policies: AmazonDynamoDBFullAccess
      Environment:
        Variables:
          REGION: us-east-2
          DYNAMODB_NAME: DBConnectionInfo

ArtifactBucket:
  Type: AWS::S3::Bucket
  DeletionPolicy: Delete
  Properties:
    BucketName:  !Sub ${AccountName}-${Region}-artifacts
    AccessControl: PublicReadWrite
    VersioningConfiguration:
    Status: Suspended

Issue: I am not quite sure how the input parameters can be passed from parent to child. I referred few links like but i was confused even more as to when the input type must be CommaDelimitedList vs string. I even tried keeping the param type to string in both parent and child but still i get below error: "Value of property Parameters must be an object with String (or simple type) properties" and on using Fn::join get error as below: "Fn::Join object requires two parameters, (1) a string delimiter and (2) a list of strings to be joined or a function that returns a list of strings (such as Fn::GetAZs) to be joined."

Have referred link : Trying to pass parameters from Master to child template but no luck . Can anyone guide me in correct direction please. Thanks in advance.

rashmi
  • 85
  • 1
  • 9

2 Answers2

1

Thanks @gandaliter for your guidance. As per above marked answer CloudFormation parent stack accepts only strings and not any object level parameters(sub parameters under parameters just like CodeURI in my above code). I did few tweaks and changed all the parent template to below : Note: All the parameter type are set to String in child and parent template

AWSTemplateFormatVersion: "2010-09-09"
Transform: 'AWS::Serverless-2016-10-31'
Description: "ParentStack with all child stack"

Parameters:

  apiGatewayStageName:
    Type: String
    Default: "dev"

  HandlerName:
    Type: String
    Default: "com.test.tehgsaLambda::handleRequest"

  S3BucketName:
    Type: String
    Default: ""

  S3KeyName:
    Type: String
    Default: "Test-LambdaFunction.zip"

Resources:
  LambdaStack1:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL:
        Fn::Sub: "https://testyu2y73.s3.us-east-2.amazonaws.com/CFTemplates/lambda.yaml"
      Parameters:
        S3BucketName: !Ref S3BucketName
        S3KeyName: !Ref S3KeyName
        HandlerName: !Ref HandlerName
        apiGatewayStageName: !Ref apiGatewayStageName

        ```
rashmi
  • 85
  • 1
  • 9
0

I imagine the code you've given above isn't the only combination you've tried, and the parameters don't exactly line up between your parent and child stack, but in any case, the problem is that you're trying to give parameter values of:

CodeUri:
  Bucket: Fn:Join [ ' ', [!Ref S3BucketName] ]
  Key: Fn::Join [ ' ', [!Ref S3KeyName] ]

and

VersioningConfiguration:
  Status: Suspended

Both of these are objects, not 'String (or simple type) properties'. The error is saying that the whole Parameters object must have only simple values.

Incidentally, TemplateURL needs to go outside the Parameters object.

gandaliter
  • 9,863
  • 1
  • 16
  • 23
  • Hello .. Yeah i have tried so many times that i have lost track now. I am bit confused with the above answer. Do you mean, that using only the string type would help me resolve my issue. Also from above "The error is saying that the whole Parameters object must have only simple values" would that mean that we cant parametrise them ? I am bit confused can you please help here. – rashmi Jan 20 '20 at 09:32
  • In your question, you’ve given all the parameter definitions in the child template the String type, but where you give values to parameters in the master stack you’re using a mixture of types, including the objects I’ve listed above. Those are what it’s complaining about. – gandaliter Jan 20 '20 at 09:34
  • Your child template above looks fine from the point of view of parameters. If you write a master stack that sets the properties you’ve defined, then it will work. In the one you’ve given, it looks like you’re trying to set nested properties, which aren’t a thing. – gandaliter Jan 20 '20 at 09:37
  • Yeah i have consolidated all my templates to write a master stack and it works fine. IF i want to use nestedstack can you please point out what changes in my parent stack i would need to do please . What would be the best approach please .. – rashmi Jan 20 '20 at 09:42
  • When you split the stack up, just make sure that you only bring through keys that are simple. If you want to bring through a whole block, then you have to split it up into several keys, and construct the block in the child stack not the parent. Think about what the values assigned to parameters are, and if you’re sending something that has subkeys, split it up (like CodeUri in the question, which needs to be split into two separate parameters). You can name them whatever you want as you’ll reference them by name in the child stack. – gandaliter Jan 20 '20 at 09:47
  • ahh i got the issue now. Would you mind pasting some reference code in case we want to split the parameters with subkeys like CodeURi in child template. I tried searching on web but probably i wasnt searching the right thing . – rashmi Jan 20 '20 at 10:07
  • Now I look at it, that’s what you’ve already done in the child template! You just need to send S3KeyName and S3BucketName instead of CodeUri! – gandaliter Jan 20 '20 at 10:09
  • Thanks a lot for your guidance. I have passed and tested the parameters as you suggested. – rashmi Jan 20 '20 at 11:20