initial-pipeline/pipeline-setup.yml [550:626]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Timeout: "35"
      MemorySize: 128

  PermissionForEventsToInvokeLambdaCBSC:
    Type: "AWS::Lambda::Permission"
    Properties:
      FunctionName: !Join [ '-', [ !Ref ResourceName, 'codebuild-secrets'  ] ]
      Action: "lambda:InvokeFunction"
      Principal: "events.amazonaws.com"
      SourceArn: !GetAtt CBSCEventRule.Arn
  
  ### Feedback Loop - Vunerability Scanning CodeBuild

  CBVCEventRule:
    Type: "AWS::Events::Rule"
    Properties:
      Name: !Join [ '-', [ !Ref ResourceName, 'codebuild-vulnerability'  ] ]
      Description: "Triggers when builds fail/pass in CodeBuild for the vulnerability scanning."
      EventPattern:
        source:
          - "aws.codebuild"
        detail-type:
          - "CodeBuild Build State Change"
        detail:
          build-status:
            - "FAILED"
            - "SUCCEEDED"
          project-name:
            - !Ref CodeBuildVulnProject
      State: "ENABLED"
      Targets:
        - Arn: !GetAtt LambdaCBVC.Arn
          Id: !Join [ '-', [ !Ref ResourceName, 'codebuild-vulnerability'  ] ]

  LambdaCBVC: 
    Type: "AWS::Lambda::Function"
    Properties: 
      FunctionName: !Join [ '-', [ !Ref ResourceName, 'codebuild-vulnerability'  ] ]
      Description: "Adds a comment to the pull request regarding the success or failure of the vulnerability scanning codebuild."
      Handler: "index.handler"
      Environment:
        Variables:
          PREFIX: !Ref ResourceName
          CODEBUILDVCPROJECT: !Ref CodeBuildVulnProject
      Role: !GetAtt 'LambdaPRCommentRole.Arn'
      Code:
        ZipFile: |
          from __future__ import print_function
          import boto3
          import os
          import json

          codecommit_client = boto3.client('codecommit')
          ssm = boto3.client('ssm')
          vcproject = os.environ['CODEBUILDVCPROJECT']

          def handler(event, context):

            # Log event
            print(json.dumps(event))

            # Get PR Details
            pull_request_id = ssm.get_parameter(
              Name='prid'
            )

            repository_name = ssm.get_parameter(
              Name='repo'
            )

            source_commit = ssm.get_parameter(
              Name='sourceCommit'
            )

            destination_commit = ssm.get_parameter(
              Name='destinationCommit'
            )
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



supplemental/pipeline-setup-final.yml [653:729]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Timeout: "35"
      MemorySize: 128

  PermissionForEventsToInvokeLambdaCBSC:
    Type: "AWS::Lambda::Permission"
    Properties:
      FunctionName: !Join [ '-', [ !Ref ResourceName, 'codebuild-secrets'  ] ]
      Action: "lambda:InvokeFunction"
      Principal: "events.amazonaws.com"
      SourceArn: !GetAtt CBSCEventRule.Arn
  
  ### Feedback Loop - Vunerability Scanning CodeBuild

  CBVCEventRule:
    Type: "AWS::Events::Rule"
    Properties:
      Name: !Join [ '-', [ !Ref ResourceName, 'codebuild-vulnerability'  ] ]
      Description: "Triggers when builds fail/pass in CodeBuild for the vulnerability scanning."
      EventPattern:
        source:
          - "aws.codebuild"
        detail-type:
          - "CodeBuild Build State Change"
        detail:
          build-status:
            - "FAILED"
            - "SUCCEEDED"
          project-name:
            - !Ref CodeBuildVulnProject
      State: "ENABLED"
      Targets:
        - Arn: !GetAtt LambdaCBVC.Arn
          Id: !Join [ '-', [ !Ref ResourceName, 'codebuild-vulnerability'  ] ]

  LambdaCBVC: 
    Type: "AWS::Lambda::Function"
    Properties: 
      FunctionName: !Join [ '-', [ !Ref ResourceName, 'codebuild-vulnerability'  ] ]
      Description: "Adds a comment to the pull request regarding the success or failure of the vulnerability scanning codebuild."
      Handler: "index.handler"
      Environment:
        Variables:
          PREFIX: !Ref ResourceName
          CODEBUILDVCPROJECT: !Ref CodeBuildVulnProject
      Role: !GetAtt 'LambdaPRCommentRole.Arn'
      Code:
        ZipFile: |
          from __future__ import print_function
          import boto3
          import os
          import json

          codecommit_client = boto3.client('codecommit')
          ssm = boto3.client('ssm')
          vcproject = os.environ['CODEBUILDVCPROJECT']

          def handler(event, context):

            # Log event
            print(json.dumps(event))

            # Get PR Details
            pull_request_id = ssm.get_parameter(
              Name='prid'
            )

            repository_name = ssm.get_parameter(
              Name='repo'
            )

            source_commit = ssm.get_parameter(
              Name='sourceCommit'
            )

            destination_commit = ssm.get_parameter(
              Name='destinationCommit'
            )
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



