Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CPMellows opened this issue Sep 3, 2021 · 1 comment

Comments

@CPMellows
Copy link

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
@CPMellows CPMellows changed the title GetAtt returns a single value when a parameter of a Fn::Select GetAtt returns a string value instead of an array when a parameter of a Fn::Select Sep 3, 2021
@oscarbc96 oscarbc96 transferred this issue from Skyscanner/cfripper Sep 3, 2021
@oscarbc96
Copy link
Contributor

Hey!
We don't have the Fn::GetAtt function implemented at the moment.

logger.warning("`Fn::GetAtt` resolver not implemented, returning `GETATT`")

GetAtt has to return values that are only known when the resource is deployed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants