aws-remediate-cis-securityhub/cft/aws-cis-securityhubactions.yml [1703:1767]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Handler: index.lambda_handler
      MemorySize: 256
      Role: !GetAtt S3BucketServerSideEncryptionEnabledLambdaRole.Arn
      Runtime: python3.7
      Timeout: 60
      Code:
        ZipFile: |
          import boto3
          import json
          import os
          def lambda_handler(event, context):
              S3BucketArn = str(event['detail']['findings'][0]['Resources'][0]['Id'])
              Id = str(event['detail']['findings'][0]['Id'])
              S3BucketName = S3BucketArn.replace("arn:aws:s3:::", "")
              SSEAlgorithm = 'AES256'
              ssm = boto3.client('ssm')
              try:
                  response = ssm.start_automation_execution(
                      DocumentName='AWS-EnableS3BucketEncryption',
                      DocumentVersion='1', # default
                      Parameters={
                          'BucketName': [ S3BucketName ],
                          'SSEAlgorithm': [SSEAlgorithm]
                      }
                  )
              except Exception as e:
                  print(e)
                  print("SSM automation execution error")
                  raise

  S3BucketServerSideEncryptionEnabledLambdaRole:
    Type: AWS::IAM::Role
    Properties:
      Policies:
      - PolicyName: S3BucketServerSideEncryptionEnabledLambdaPolicy
        PolicyDocument:
          Version: 2012-10-17
          Statement:
          - Effect: Allow
            Action:
            - cloudwatch:PutMetricData
            Resource: '*'
          - Effect: Allow
            Action:
            - ssm:StartAutomationExecution
            - logs:CreateLogGroup
            - logs:CreateLogStream
            - logs:PutLogEvents
            - logs:DescribeLogGroups
            - iam:PassRole
            - s3:*
            - kms:*
            Resource: '*'
          - Effect: Allow
            Action:
            - cloudtrail:UpdateTrail
            - securityhub:UpdateFindings
            Resource: '*'
      AssumeRolePolicyDocument:
        Version: 2012-10-17
        Statement:
        - Effect: Allow
          Principal: { Service: lambda.amazonaws.com }
          Action:
          - sts:AssumeRole
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



aws-remediate-pci-securityhub/cft/aws-security-hub-pci-remediations-template2.yml [2296:2360]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Handler: index.lambda_handler
      MemorySize: 256
      Role: !GetAtt S3BucketServerSideEncryptionEnabledLambdaRole.Arn
      Runtime: python3.7
      Timeout: 60
      Code:
        ZipFile: |
          import boto3
          import json
          import os
          def lambda_handler(event, context):
              S3BucketArn = str(event['detail']['findings'][0]['Resources'][0]['Id'])
              Id = str(event['detail']['findings'][0]['Id'])
              S3BucketName = S3BucketArn.replace("arn:aws:s3:::", "")
              SSEAlgorithm = 'AES256'
              ssm = boto3.client('ssm')
              try:
                  response = ssm.start_automation_execution(
                      DocumentName='AWS-EnableS3BucketEncryption',
                      DocumentVersion='1', # default
                      Parameters={
                          'BucketName': [ S3BucketName ],
                          'SSEAlgorithm': [SSEAlgorithm]
                      }
                  )
              except Exception as e:
                  print(e)
                  print("SSM automation execution error")
                  raise

  S3BucketServerSideEncryptionEnabledLambdaRole:
    Type: AWS::IAM::Role
    Properties:
      Policies:
      - PolicyName: S3BucketServerSideEncryptionEnabledLambdaPolicy
        PolicyDocument:
          Version: 2012-10-17
          Statement:
          - Effect: Allow
            Action:
            - cloudwatch:PutMetricData
            Resource: '*'
          - Effect: Allow
            Action:
            - ssm:StartAutomationExecution
            - logs:CreateLogGroup
            - logs:CreateLogStream
            - logs:PutLogEvents
            - logs:DescribeLogGroups
            - iam:PassRole
            - s3:*
            - kms:*
            Resource: '*'
          - Effect: Allow
            Action:
            - cloudtrail:UpdateTrail
            - securityhub:UpdateFindings
            Resource: '*'
      AssumeRolePolicyDocument:
        Version: 2012-10-17
        Statement:
        - Effect: Allow
          Principal: { Service: lambda.amazonaws.com }
          Action:
          - sts:AssumeRole
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



