Skip to content

GetAtt returns a string value instead of an array when a parameter of a Fn::Select  #75

@CPMellows

Description

Upon using the --resolve flag on a template containing a Select that retrieves its array using a GetAtt, the Attribute returned is a single value instead of an array.

I'm able to get the Error to disappear by creating a parameter file containing the object
{"ApiGatewayEndpoint":{"DnsEntries":["String"]}}
But as my use case is as a general scanning tool for checking in code defining every Ref in a prameters file and using --resolve-parameters isn't an option.

Template

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "The AWS CloudFormation template for this Serverless application",
  "Resources": {
    "UsageRetryLambdaFunction": {
      "Type": "AWS::Lambda::Function",
      "Properties": {
        "Code": {
          "S3Bucket": "Bucket",
          "S3Key": "retry-lambda/function.zip"
        },
        "Runtime": "java11",
        "FunctionName": "Retry-Lambda",
        "MemorySize": 512,
        "Timeout": 300,
        "KmsKeyArn": "arn:aws:kms:ap-south-1:123456789012:key/a-key",
        "Environment": {
          "Variables": {
            "API_ENDPOINT": {
              "Fn::Join": [
                "",
                [
                  "https://",
                  {
                    "Fn::Select": [
                      "1",
                      {
                        "Fn::Split": [
                          ":",
                          {
                            "Fn::Select": [
                              "0",
                              {
                                "Fn::GetAtt": [
                                  "ApiGatewayEndpoint",
                                  "DnsEntries"
                                ]
                              }
                            ]
                          }
                        ]
                      }
                    ]
                  },
                  "/prod/api/usage"
                ]
              ]
            },
            "API_ID": "asdfghghjk",
            "HTTP_RETRY": "3"
          }
        },
        "Role": "arn:aws:iam::123456789012:role/retry-prod-ap-south-1-lambdaRole",
        "VpcConfig": {
          "SecurityGroupIds": ["sg-123456789"],
          "SubnetIds": [
            {
              "Fn::ImportValue": "PrivateA-SubnetID"
            },
            {
              "Fn::ImportValue": "PrivateB-SubnetID"
            }
          ]
        },
        "ReservedConcurrentExecutions": 10
      }
    },
    "ApiGatewayEndpoint": {
      "Type": "AWS::EC2::VPCEndpoint",
      "Properties": {
        "ServiceName": {
          "Fn::Sub": "com.amazonaws.us-east-1.execute-api"
        },
        "SecurityGroupIds": [
          {
            "Ref": "VpcEndpointSecurityGroup"
          }
        ],
        "SubnetIds": ["subnet-111111", "subnet-222222", "subnet-333333"],
        "VpcId": "vpc-1234567",
        "VpcEndpointType": "Interface"
      }
    }
  }
}

Output

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/cfripper/cli.py", line 222, in cli
    results_of_templates = [
  File "/usr/local/lib/python3.9/site-packages/cfripper/cli.py", line 223, in <listcomp>
    process_template(template=template, resolve_parameters=resolve_parameters, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/cfripper/cli.py", line 119, in process_template
    cfmodel = cfmodel.resolve(resolve_parameters)
  File "/usr/local/lib/python3.9/site-packages/pycfmodel/model/cf_model.py", line 87, in resolve
    resolved_resources = {
  File "/usr/local/lib/python3.9/site-packages/pycfmodel/model/cf_model.py", line 88, in <dictcomp>
    key: resolve(value, extended_parameters, self.Mappings, resolved_conditions)
  File "/usr/local/lib/python3.9/site-packages/pycfmodel/resolver.py", line 54, in resolve
    resolved_value = resolve(v, params, mappings, conditions)
  File "/usr/local/lib/python3.9/site-packages/pycfmodel/resolver.py", line 54, in resolve
    resolved_value = resolve(v, params, mappings, conditions)
  File "/usr/local/lib/python3.9/site-packages/pycfmodel/resolver.py", line 54, in resolve
    resolved_value = resolve(v, params, mappings, conditions)
  [Previous line repeated 1 more time]
  File "/usr/local/lib/python3.9/site-packages/pycfmodel/resolver.py", line 50, in resolve
    return function_resolver(function[function_name], params, mappings, conditions)
  File "/usr/local/lib/python3.9/site-packages/pycfmodel/resolver.py", line 84, in resolve_join
    resolved_list = resolve(list_values, params, mappings, conditions)
  File "/usr/local/lib/python3.9/site-packages/pycfmodel/resolver.py", line 41, in resolve
    resolved_value = resolve(entry, params, mappings, conditions)
  File "/usr/local/lib/python3.9/site-packages/pycfmodel/resolver.py", line 50, in resolve
    return function_resolver(function[function_name], params, mappings, conditions)
  File "/usr/local/lib/python3.9/site-packages/pycfmodel/resolver.py", line 125, in resolve_select
    return resolved_list[resolved_index]
IndexError: list index out of range

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions