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

"@cR.botLocales=" is not allowed as an instance variable name (NameError) #600

Open
ktraam opened this issue Jun 29, 2022 · 0 comments
Open

Comments

@ktraam
Copy link

ktraam commented Jun 29, 2022

Describe the Bug

cfn_nag Version: 0.8.10 (build 97717cb)

Amazon Lex V2 Custom Resource with property "CR.botLocales" breaks cfn_nag command and throws error due to not being apart of instance variable names.

Expected Behavior

cfn_nag command runs successfully on the AWS SAM template.

Current Behavior

When running

cfn_nag test.yaml

I receive the following error:

Traceback (most recent call last):
	16: from /usr/local/bin/cfn_nag:23:in `<main>'
	15: from /usr/local/bin/cfn_nag:23:in `load'
	14: from /Library/Ruby/Gems/2.6.0/gems/cfn-nag-0.8.10/bin/cfn_nag:11:in `<top (required)>'
	13: from /Library/Ruby/Gems/2.6.0/gems/cfn-nag-0.8.10/lib/cfn-nag/cfn_nag_executor.rb:30:in `scan'
	12: from /Library/Ruby/Gems/2.6.0/gems/cfn-nag-0.8.10/lib/cfn-nag/cfn_nag_executor.rb:39:in `execute_file_or_piped_scan'
	11: from /Library/Ruby/Gems/2.6.0/gems/cfn-nag-0.8.10/lib/cfn-nag/cfn_nag_executor.rb:60:in `scan_file'
	10: from /Library/Ruby/Gems/2.6.0/gems/cfn-nag-0.8.10/lib/cfn-nag/cfn_nag.rb:87:in `audit'
	 9: from /Library/Ruby/Gems/2.6.0/gems/cfn-model-0.6.6/lib/cfn-model/parser/cfn_parser.rb:43:in `parse'
	 8: from /Library/Ruby/Gems/2.6.0/gems/cfn-model-0.6.6/lib/cfn-model/parser/cfn_parser.rb:86:in `parse_without_parameters'
	 7: from /Library/Ruby/Gems/2.6.0/gems/cfn-model-0.6.6/lib/cfn-model/parser/cfn_parser.rb:165:in `transform_hash_into_model_elements_with_numbers'
	 6: from /Library/Ruby/Gems/2.6.0/gems/cfn-model-0.6.6/lib/cfn-model/parser/cfn_parser.rb:165:in `each'
	 5: from /Library/Ruby/Gems/2.6.0/gems/cfn-model-0.6.6/lib/cfn-model/parser/cfn_parser.rb:173:in `block in transform_hash_into_model_elements_with_numbers'
	 4: from /Library/Ruby/Gems/2.6.0/gems/cfn-model-0.6.6/lib/cfn-model/parser/cfn_parser.rb:255:in `assign_fields_based_upon_properties'
	 3: from /Library/Ruby/Gems/2.6.0/gems/cfn-model-0.6.6/lib/cfn-model/parser/cfn_parser.rb:255:in `each'
	 2: from /Library/Ruby/Gems/2.6.0/gems/cfn-model-0.6.6/lib/cfn-model/parser/cfn_parser.rb:257:in `block in assign_fields_based_upon_properties'
	 1: from /Library/Ruby/Gems/2.6.0/gems/cfn-model-0.6.6/lib/cfn-model/model/model_element.rb:101:in `method_missing'
/Library/Ruby/Gems/2.6.0/gems/cfn-model-0.6.6/lib/cfn-model/model/model_element.rb:101:in `instance_variable_get': `@cR.botLocales=' is not allowed as an instance variable name (NameError)

Reproduction Steps

Generate the following test.yaml file from lex-v2-cfn-cr:

Parameters:
  # add a parameter to your bot template to reference the Custom Resource stack
  LexV2CfnCrStackName:
    Description: >-
      Existing Lex V2 Custom Resource Stack Name. This is used to import the
      Lambda function and IAM role provisioned by the Custom Resource stack
    Type: String
    # If you deployed via the SAR Console and used the defaults, your stack
    # will be named serverlessrepo-lex-v2-cfn-cr. If you deployed manually,
    # make it match the name of your Custom Resource stack
    Default: serverlessrepo-lex-v2-cfn-cr

Resources:
  # LexBot resource contains the bot definition and subresources including:
  # locales, slot types, intents and slots. These subresources use custom
  # attributes with a name prefix: CR.<subresource name>
  # The changes are done to the DRAFT version of the bot.
  # All locales are automatically built
  LexBot:
    Type: Custom::LexBot
    Properties:
      ServiceToken:
        # Points to the Custom Resource Lambda function
        !ImportValue
          Fn::Sub: "${LexV2CfnCrStackName}-LexV2CfnCrFunctionArn"
      # Bot level attributes
      # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lexv2-models.html#LexModelsV2.Client.create_bot
      botName:
        ZipCodeUpdateBot
      dataPrivacy:
        childDirected: True
      description: Test bot deployed using CloudFormation Custom Resource
      idleSessionTTLInSeconds: 300
      roleArn:
        # Points to the Custom Resource IAM Service Linked role
        !ImportValue
          Fn::Sub: "${LexV2CfnCrStackName}-LexServiceLinkedRole"
      # List of Bot Locale definitions. Requires one or more locales
      CR.botLocales:
        # Locale level attributes
        # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lexv2-models.html#LexModelsV2.Client.create_bot_locale
        - localeId: en_US
          nluIntentConfidenceThreshold: 0.40
          voiceSettings:
            voiceId: Salli
          # List of optional Slot Type definitions
          CR.slotTypes:
            # Slot Type level attributes
            # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lexv2-models.html#LexModelsV2.Client.create_slot_type
            - slotTypeName: ZipCodeType
              parentSlotTypeSignature: AMAZON.AlphaNumeric
              valueSelectionSetting:
                resolutionStrategy: OriginalValue
                regexFilter:
                  pattern: '[0-9]{8}'
          # List of Intent definitions. Requires one or more Intents
          CR.intents:
              # Intent level attributes
              # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lexv2-models.html#LexModelsV2.Client.create_intent
            - intentName: UpdateZipCode
              sampleUtterances:
                - utterance: i want to change my zip code
                - utterance: i have a new zip code
                - utterance: my new zip code is {ZipCode}
               # List of optional Slot definitions. Defined in order of slot priority
              CR.slots:
                # Slot level attributes
                # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lexv2-models.html#LexModelsV2.Client.create_slot
                - slotName: ZipCode
                  # Slot Type Name is used to dyanmically resolve the ID of the
                  # associated Slot Type defined above
                  CR.slotTypeName: ZipCodeType
                  valueElicitationSetting:
                    slotConstraint: Required
                    promptSpecification:
                      messageGroups:
                        - message:
                            plainTextMessage:
                              value: What is your zipcode?
                      maxRetries: 2
                      allowInterrupt: true
            # The Fallback intent is automatically created by the Lex service
            # This will update the default fallback intent
            - intentName: FallbackIntent
              description: Default fallback intent when no other intent matches
              intentClosingSetting:
                closingResponse:
                  messageGroups:
                    - message:
                        plainTextMessage:
                          value: Sorry I am having trouble understanding.

  # Creates an immutable Bot Version
  LexBotVersion:
    # Bot versions are deleted by the Bot on Stack deletions. This deletion
    # policy speeds up deletes
    DeletionPolicy: Retain
    # Version number changes between updates which cause a CloudFormation
    # delete event since the version number is the physical resource ID.
    # The following policies prevents deletion events to retain the bot versions
    # and speed up updates
    UpdateReplacePolicy: Retain
    Type: Custom::LexBotVersion
    Properties:
      ServiceToken:
        !ImportValue
          Fn::Sub: "${LexV2CfnCrStackName}-LexV2CfnCrFunctionArn"
      # Bot Version level attributes
      # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lexv2-models.html#LexModelsV2.Client.create_bot_version
      botId: !Ref LexBot
      # botVersionLocaleSpecification is derived from the bot locales
      # this controls which locales are added to the version
      CR.botLocaleIds: !GetAtt LexBot.botLocaleIds
      # lastUpdatedDateTime is used to detect changes in the bot
      CR.lastUpdatedDateTime: !GetAtt LexBot.lastUpdatedDateTime

  # Provisions a Bot Alias that points to a version
  LexBotAlias:
    # Bot aliases are deleted by the Bot on Stack deletions. This deletion
    # policy speeds up deletes
    DeletionPolicy: Retain
    Type: Custom::LexBotAlias
    Properties:
      ServiceToken:
        !ImportValue
          Fn::Sub: "${LexV2CfnCrStackName}-LexV2CfnCrFunctionArn"
      # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lexv2-models.html#LexModelsV2.Client.create_bot_alias
      botId: !Ref LexBot
      botAliasName: live
      # points to the latest version of the resource above
      botVersion: !Ref LexBotVersion
      # enable locales under this alias
      botAliasLocaleSettings:
        en_US:
          enabled: True

Outputs:
  LexBotId:
    Description: Lex Bot ID
    Value: !Ref LexBot

  LexBotLocaleIds:
    Description: Lex Bot Locale IDs
    Value: !Join [",", !GetAtt LexBot.botLocaleIds]

  LexBotLatestVersion:
    Description: Latest Lex Bot Version ID
    Value: !Ref LexBotVersion

  LexBotAliasId:
    Description: Lex Bot Alias ID
    Value: !Ref LexBotAlias

Run the command:

cfn_nag test.yaml

Possible Solution

N/A

Additional Information / Context

Ruby Version

3.0.3

OS

macOS Big Sur 11.6.5

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

1 participant