templates/analytics-main.template.yaml [305:431]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Conditions:
  UsingDefaultBucket: 
    Fn::Equals: 
    - !Ref QSS3BucketName
    - 'aws-quickstart'

Resources:
  LambdaFunctionIAMRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
        - Effect: Allow
          Principal:
            Service:
            - lambda.amazonaws.com
            - s3.amazonaws.com
          Action:
          - sts:AssumeRole
      Path: "/"

  LambdaFunctionIAMPolicy:
    Type: AWS::IAM::Policy
    Properties:
      PolicyName: !Join
        - ''
        - - !Ref 'LambdaFunctionIAMRole'
          - _policy
      Roles:
      - Ref: LambdaFunctionIAMRole
      PolicyDocument:
        Version: '2012-10-17'
        Statement:
        - Effect: Allow
          Action:
          - "logs:CreateLogGroup"
          - "logs:CreateLogStream"
          - "logs:PutLogEvents"
          Resource:
          - arn:aws:logs:*:*:*
        - Effect: Allow
          Action:
          - "s3:GetObject"
          - "s3:GetObjectTagging"
          - "s3:PutObject"
          - "s3:PutObjectTagging"
          - "s3:DeleteObject"
          Resource:
          - "arn:aws:s3:*:*:accesspoint/*"
          - !Join
            - ''
            - - 'arn:aws:s3:::'
              - !Ref RegionalArtifactBucket
          - !Join
            - ''
            - - 'arn:aws:s3:::'
              - !Ref RegionalArtifactBucket
              - '/*'
          - !Join
            - ''
            - - 'arn:aws:s3:::'
              - !Ref QSS3BucketName
          - !Join
            - ''
            - - 'arn:aws:s3:::'
              - !Ref QSS3BucketName
              - '/*'
        - Effect: Allow
          Action:
          - "iam:GetRole"
          - "iam:PassRole"
          Resource:
          - !GetAtt LambdaFunctionIAMRole.Arn
        - Effect: Allow
          Action:
          - lambda:InvokeFunction
          Resource:
          - "*"
  
  RegionalArtifactBucket:
    Type: AWS::S3::Bucket

  CopyZipsFunction:
    DependsOn:
    - LambdaFunctionIAMPolicy
    Type: AWS::Lambda::Function
    Properties:
      Description: Copies objects from a source S3 bucket to a destination.
      Handler: index.handler
      Runtime: python3.6
      Role: !GetAtt LambdaFunctionIAMRole.Arn
      Timeout: 240
      Code:
        ZipFile: !Join
          - "\n"
          - - import json
            - import logging
            - import threading
            - import boto3
            - import cfnresponse
            - ''
            - 'def copy_objects(source_bucket, dest_bucket, prefix, objects):'
            - '   s3 = boto3.client(''s3'')'
            - '   for o in objects:'
            - '       key = prefix + o'
            - '       copy_source = {'
            - '           ''Bucket'': source_bucket,'
            - '           ''Key'': key'
            - '       }'
            - '       print((''copy_source: %s'' % copy_source))'
            - '       print((''dest_bucket = %s''%dest_bucket))'
            - '       print((''key = %s'' %key))'
            - '       s3.copy_object(CopySource=copy_source, Bucket=dest_bucket,'
            - '             Key=key)'
            - ''
            - 'def delete_objects(bucket, prefix, objects):'
            - '   s3 = boto3.client(''s3'')'
            - '   objects = {''Objects'': [{''Key'': prefix + o} for o in objects]}'
            - '   s3.delete_objects(Bucket=bucket, Delete=objects)'
            - ''
            - 'def timeout(event, context):'
            - '   logging.error(''Execution is about to time out, sending failure
              response to CloudFormation'')'
            - '   cfnresponse.send(event, context, cfnresponse.FAILED, {}, None)'
            - ''
            - 'def handler(event, context):'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



templates/analytics.template.yaml [179:306]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Conditions:
  UsingDefaultBucket: 
    Fn::Equals: 
    - !Ref QSS3BucketName
    - 'aws-quickstart'


Resources:
  LambdaFunctionIAMRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
        - Effect: Allow
          Principal:
            Service:
            - lambda.amazonaws.com
            - s3.amazonaws.com
          Action:
          - sts:AssumeRole
      Path: "/"

  LambdaFunctionIAMPolicy:
    Type: AWS::IAM::Policy
    Properties:
      PolicyName: !Join
        - ''
        - - !Ref 'LambdaFunctionIAMRole'
          - _policy
      Roles:
      - Ref: LambdaFunctionIAMRole
      PolicyDocument:
        Version: '2012-10-17'
        Statement:
        - Effect: Allow
          Action:
          - "logs:CreateLogGroup"
          - "logs:CreateLogStream"
          - "logs:PutLogEvents"
          Resource:
          - arn:aws:logs:*:*:*
        - Effect: Allow
          Action:
          - "s3:GetObject"
          - "s3:GetObjectTagging"
          - "s3:PutObject"
          - "s3:PutObjectTagging"
          - "s3:DeleteObject"
          Resource:
          - "arn:aws:s3:*:*:accesspoint/*"
          - !Join
            - ''
            - - 'arn:aws:s3:::'
              - !Ref RegionalArtifactBucket
          - !Join
            - ''
            - - 'arn:aws:s3:::'
              - !Ref RegionalArtifactBucket
              - '/*'
          - !Join
            - ''
            - - 'arn:aws:s3:::'
              - !Ref QSS3BucketName
          - !Join
            - ''
            - - 'arn:aws:s3:::'
              - !Ref QSS3BucketName
              - '/*'
        - Effect: Allow
          Action:
          - "iam:GetRole"
          - "iam:PassRole"
          Resource:
          - !GetAtt LambdaFunctionIAMRole.Arn
        - Effect: Allow
          Action:
          - lambda:InvokeFunction
          Resource:
          - "*"
  
  RegionalArtifactBucket:
    Type: AWS::S3::Bucket

  CopyZipsFunction:
    DependsOn:
    - LambdaFunctionIAMPolicy
    Type: AWS::Lambda::Function
    Properties:
      Description: Copies objects from a source S3 bucket to a destination.
      Handler: index.handler
      Runtime: python3.6
      Role: !GetAtt LambdaFunctionIAMRole.Arn
      Timeout: 240
      Code:
        ZipFile: !Join
          - "\n"
          - - import json
            - import logging
            - import threading
            - import boto3
            - import cfnresponse
            - ''
            - 'def copy_objects(source_bucket, dest_bucket, prefix, objects):'
            - '   s3 = boto3.client(''s3'')'
            - '   for o in objects:'
            - '       key = prefix + o'
            - '       copy_source = {'
            - '           ''Bucket'': source_bucket,'
            - '           ''Key'': key'
            - '       }'
            - '       print((''copy_source: %s'' % copy_source))'
            - '       print((''dest_bucket = %s''%dest_bucket))'
            - '       print((''key = %s'' %key))'
            - '       s3.copy_object(CopySource=copy_source, Bucket=dest_bucket,'
            - '             Key=key)'
            - ''
            - 'def delete_objects(bucket, prefix, objects):'
            - '   s3 = boto3.client(''s3'')'
            - '   objects = {''Objects'': [{''Key'': prefix + o} for o in objects]}'
            - '   s3.delete_objects(Bucket=bucket, Delete=objects)'
            - ''
            - 'def timeout(event, context):'
            - '   logging.error(''Execution is about to time out, sending failure
              response to CloudFormation'')'
            - '   cfnresponse.send(event, context, cfnresponse.FAILED, {}, None)'
            - ''
            - 'def handler(event, context):'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



