initial-pipeline/pipeline-setup.yml [444:520]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Timeout: "35"
      MemorySize: 128

  PermissionForEventsToInvokeLambdaCBDF:
    Type: "AWS::Lambda::Permission"
    Properties:
      FunctionName: !Join [ '-', [ !Ref ResourceName, 'codebuild-dockerfile'  ] ]
      Action: "lambda:InvokeFunction"
      Principal: "events.amazonaws.com"
      SourceArn: !GetAtt CBDFEventRule.Arn

  ### Feedback Loop - Secrets Scanning CodeBuild

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

  LambdaCBSC: 
    Type: "AWS::Lambda::Function"
    Properties: 
      FunctionName: !Join [ '-', [ !Ref ResourceName, 'codebuild-secrets'  ] ]
      Description: "Adds a comment to the pull request regarding the success or failure of the secrets analysis codebuild."
      Handler: "index.handler"
      Environment:
        Variables:
          PREFIX: !Ref ResourceName
          CODEBUILDSCPROJECT: !Ref CodeBuildSecretsProject
      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')
          scproject = os.environ['CODEBUILDSCPROJECT']

          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 [539:615]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Timeout: "35"
      MemorySize: 128

  PermissionForEventsToInvokeLambdaCBDF:
    Type: "AWS::Lambda::Permission"
    Properties:
      FunctionName: !Join [ '-', [ !Ref ResourceName, 'codebuild-dockerfile'  ] ]
      Action: "lambda:InvokeFunction"
      Principal: "events.amazonaws.com"
      SourceArn: !GetAtt CBDFEventRule.Arn

  ### Feedback Loop - Secrets Scanning CodeBuild

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

  LambdaCBSC: 
    Type: "AWS::Lambda::Function"
    Properties: 
      FunctionName: !Join [ '-', [ !Ref ResourceName, 'codebuild-secrets'  ] ]
      Description: "Adds a comment to the pull request regarding the success or failure of the secrets analysis codebuild."
      Handler: "index.handler"
      Environment:
        Variables:
          PREFIX: !Ref ResourceName
          CODEBUILDSCPROJECT: !Ref CodeBuildSecretsProject
      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')
          scproject = os.environ['CODEBUILDSCPROJECT']

          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'
            )
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



