AWSTemplateFormatVersion: "2010-09-09"
Description: >
  Testing for IS DEFINED rule
Parameter:
  NodeEnv:
    Type: String
Resources:
  LambdaExecutionRole:
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action:
              - sts:AssumeRole
            Effect: Allow
            Principal:
              Service:
                - lambda.amazonaws.com
                - ec2.amazonaws.com
        Version: "2012-10-17"
      Path: "/"
    Type: AWS::IAM::Role
  LambdaFunctionTestDefinedArray:
    Properties:
      Code: ./
      Environment:
        Variables:
          NODE_ENV:
            - 1
            - 2
      Handler: index.handler
      Role: !GetAtt "LambdaExecutionRole.Arn"
      Runtime: nodejs18.x
    Type: AWS::Lambda::Function
  LambdaFunctionTestDefinedEmpty:
    Properties:
      Code: ./
      Environment:
        Variables:
          NODE_ENV: ""
      Handler: index.handler
      Role: !GetAtt "LambdaExecutionRole.Arn"
      Runtime: nodejs18.x
    Type: AWS::Lambda::Function
  LambdaFunctionTestDefinedGetAttr:
    Properties:
      Code: ./
      Environment:
        Variables:
          NODE_ENV: !GetAtt "LambdaExecutionRole.Arn"
      Handler: index.handler
      Role: !GetAtt "LambdaExecutionRole.Arn"
      Runtime: nodejs18.x
    Type: AWS::Lambda::Function
  LambdaFunctionTestDefinedObject:
    Properties:
      Code: ./
      Environment:
        Variables:
          NODE_ENV:
            A: 1
      Handler: index.handler
      Role: !GetAtt "LambdaExecutionRole.Arn"
      Runtime: nodejs18.x
    Type: AWS::Lambda::Function
  LambdaFunctionTestDefinedRef:
    Properties:
      Code: ./
      Environment:
        Variables:
          NODE_ENV: !Ref 'NodeEnv'
      Handler: index.handler
      Role: !GetAtt "LambdaExecutionRole.Arn"
      Runtime: nodejs18.x
    Type: AWS::Lambda::Function
  LambdaFunctionTestDefinedValue:
    Properties:
      Code: ./
      Environment:
        Variables:
          NODE_ENV: value
      Handler: index.handler
      Role: !GetAtt "LambdaExecutionRole.Arn"
      Runtime: nodejs18.x
    Type: AWS::Lambda::Function
