Resources:
  hclsws1440A5E22:
    Type: AWS::S3::Bucket
    UpdateReplacePolicy: Delete
    DeletionPolicy: Delete
    Metadata:
      aws:cdk:path: HclsWorkshop1Stack/hcls-ws1/Resource
  hclsws1lambdaroleDE4EB09C:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service: lambda.amazonaws.com
        Version: "2012-10-17"
      ManagedPolicyArns:
        - Fn::Join:
            - ""
            - - "arn:"
              - Ref: AWS::Partition
              - :iam::aws:policy/AmazonKinesisFirehoseFullAccess
        - Fn::Join:
            - ""
            - - "arn:"
              - Ref: AWS::Partition
              - :iam::aws:policy/ComprehendMedicalFullAccess
      Path: /service-role/
      Policies:
        - PolicyDocument:
            Statement:
              - Action:
                  - logs:CreateLogGroup
                  - logs:CreateLogStream
                  - logs:PutLogEvents
                Effect: Allow
                Resource: "*"
            Version: "2012-10-17"
          PolicyName: DemoLambdaPolicy
    Metadata:
      aws:cdk:path: HclsWorkshop1Stack/hcls-ws1-lambda-role/Resource
  hclsws1glueroleB6A0DD4D:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service: glue.amazonaws.com
        Version: "2012-10-17"
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/service-role/AWSGlueServiceRole
      Path: /service-role/
      Policies:
        - PolicyDocument:
            Statement:
              - Action:
                  - s3:GetObject
                  - s3:PutObject
                Effect: Allow
                Resource:
                  Fn::Join:
                    - ""
                    - - Fn::GetAtt:
                          - hclsws1440A5E22
                          - Arn
                      - /*
            Version: "2012-10-17"
          PolicyName: GluePolicy
      RoleName: hcls-ws1-glue-role
    Metadata:
      aws:cdk:path: HclsWorkshop1Stack/hcls-ws1-glue-role/Resource
  firehoseRoleE5891AF8:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service: firehose.amazonaws.com
        Version: "2012-10-17"
      Policies:
        - PolicyDocument:
            Statement:
              - Action:
                  - logs:CreateLogGroup
                  - logs:CreateLogStream
                  - logs:PutLogEvents
                  - glue:GetTable
                  - glue:GetTableVersion
                  - glue:GetTableVersions
                  - sts:AssumeRole
                Effect: Allow
                Resource: "*"
            Version: "2012-10-17"
          PolicyName: FSPolicy
    Metadata:
      aws:cdk:path: HclsWorkshop1Stack/firehoseRole/Resource
  firehoseRoleDefaultPolicy27F13165:
    Type: AWS::IAM::Policy
    Properties:
      PolicyDocument:
        Statement:
          - Action:
              - s3:AbortMultipartUpload
              - s3:GetBucketLocation
              - s3:GetObject
              - s3:ListBucket
              - s3:ListBucketMultipartUploads
              - s3:PutObject
            Effect: Allow
            Resource:
              - Fn::GetAtt:
                  - hclsws1440A5E22
                  - Arn
              - Fn::Join:
                  - ""
                  - - Fn::GetAtt:
                        - hclsws1440A5E22
                        - Arn
                    - /*
          - Action:
              - lambda:InvokeFunction
              - lambda:GetFunctionConfiguration
              - kinesis:DescribeStream
              - kinesis:GetShardIterator
              - kinesis:GetRecords
              - kms:Decrypt
              - kms:GenerateDataKey
            Effect: Allow
            Resource: "*"
        Version: "2012-10-17"
      PolicyName: firehoseRoleDefaultPolicy27F13165
      Roles:
        - Ref: firehoseRoleE5891AF8
    Metadata:
      aws:cdk:path: HclsWorkshop1Stack/firehoseRole/DefaultPolicy/Resource
  hclsws1glue:
    Type: AWS::Glue::Crawler
    Properties:
      Role:
        Fn::GetAtt:
          - hclsws1glueroleB6A0DD4D
          - Arn
      Targets:
        S3Targets:
          - Path:
              Fn::Join:
                - ""
                - - s3://
                  - Ref: hclsws1440A5E22
      DatabaseName: hcls-ws1-db
      Name: hcls-ws1-crawler
      Schedule:
        ScheduleExpression: cron(1/5 * * * ? *)
    Metadata:
      aws:cdk:path: HclsWorkshop1Stack/hcls-ws1-glue
  hclsws1firehose:
    Type: AWS::KinesisFirehose::DeliveryStream
    Properties:
      DeliveryStreamName: hcls-ws1-firehose
      DeliveryStreamType: DirectPut
      S3DestinationConfiguration:
        BucketARN:
          Fn::GetAtt:
            - hclsws1440A5E22
            - Arn
        RoleARN:
          Fn::GetAtt:
            - firehoseRoleE5891AF8
            - Arn
    Metadata:
      aws:cdk:path: HclsWorkshop1Stack/hcls-ws1-firehose
  ws1layerFCC4CBEA:
    Type: AWS::Lambda::LayerVersion
    Properties:
      Content:
        S3Bucket: 'aws-jp-hcls-handson-shared-private'
        S3Key: 'handson1/assets/03deae7b8b43f8ad03cf0fbc5687d94adf0bf47b3932230a3d74f251caafb0ce.zip'
      CompatibleRuntimes:
        - python3.7
      LayerName: hcls-ws1-layer
    Metadata:
      aws:cdk:path: HclsWorkshop1Stack/ws1-layer/Resource
      aws:asset:path: asset.03deae7b8b43f8ad03cf0fbc5687d94adf0bf47b3932230a3d74f251caafb0ce
      aws:asset:property: Content
  ws1lambdaC8BEAF5B:
    Type: AWS::Lambda::Function
    Properties:
      Code:
        S3Bucket: 'aws-jp-hcls-handson-shared-private'
        S3Key: 'handson1/assets/4a27d3d31bed2752a6d6ed90ce2136b7d50e04573e831387851f23a2d1bacc7d.zip'
      Handler: lambda_function.lambda_handler
      Role:
        Fn::GetAtt:
          - hclsws1lambdaroleDE4EB09C
          - Arn
      Runtime: python3.7
      Environment:
        Variables:
          term: !Ref Term
          mindate: !Ref MinDate
          maxdate: !Ref MaxDate
          KinesisDataFirehoseName: hcls-ws1-firehose
      FunctionName: ws1-lambda
      Layers:
        - Ref: ws1layerFCC4CBEA
      MemorySize: 2048
      Timeout: 600
    DependsOn:
      - hclsws1lambdaroleDE4EB09C
    Metadata:
      aws:cdk:path: HclsWorkshop1Stack/ws1-lambda/Resource
      aws:asset:path: asset.4a27d3d31bed2752a6d6ed90ce2136b7d50e04573e831387851f23a2d1bacc7d
      aws:asset:property: Code
  ws1lambdaAllowEventRuleHclsWorkshop1Stackws1cwe5A6E2226E3CF7A92:
    Type: AWS::Lambda::Permission
    Properties:
      Action: lambda:InvokeFunction
      FunctionName:
        Fn::GetAtt:
          - ws1lambdaC8BEAF5B
          - Arn
      Principal: events.amazonaws.com
      SourceArn:
        Fn::GetAtt:
          - ws1cweDA114C92
          - Arn
    Metadata:
      aws:cdk:path: HclsWorkshop1Stack/ws1-lambda/AllowEventRuleHclsWorkshop1Stackws1cwe5A6E2226
  ws1cweDA114C92:
    Type: AWS::Events::Rule
    Properties:
      Name: ws1-cwe
      ScheduleExpression: rate(5 minutes)
      State: ENABLED
      Targets:
        - Arn:
            Fn::GetAtt:
              - ws1lambdaC8BEAF5B
              - Arn
          Id: Target0
    Metadata:
      aws:cdk:path: HclsWorkshop1Stack/ws1-cwe/Resource
  CDKMetadata:
    Type: AWS::CDK::Metadata
    Properties:
      Modules: aws-cdk=1.51.0,@aws-cdk/assets=1.51.0,@aws-cdk/aws-applicationautoscaling=1.51.0,@aws-cdk/aws-autoscaling=1.51.0,@aws-cdk/aws-autoscaling-common=1.51.0,@aws-cdk/aws-autoscaling-hooktargets=1.51.0,@aws-cdk/aws-cloudwatch=1.51.0,@aws-cdk/aws-ec2=1.51.0,@aws-cdk/aws-ecr=1.51.0,@aws-cdk/aws-ecr-assets=1.51.0,@aws-cdk/aws-ecs=1.51.0,@aws-cdk/aws-elasticloadbalancingv2=1.51.0,@aws-cdk/aws-events=1.51.0,@aws-cdk/aws-events-targets=1.51.0,@aws-cdk/aws-glue=1.51.0,@aws-cdk/aws-iam=1.51.0,@aws-cdk/aws-kinesisfirehose=1.51.0,@aws-cdk/aws-kms=1.51.0,@aws-cdk/aws-lambda=1.51.0,@aws-cdk/aws-logs=1.51.0,@aws-cdk/aws-s3=1.51.0,@aws-cdk/aws-s3-assets=1.51.0,@aws-cdk/aws-servicediscovery=1.51.0,@aws-cdk/aws-sns=1.51.0,@aws-cdk/aws-sns-subscriptions=1.51.0,@aws-cdk/aws-sqs=1.51.0,@aws-cdk/aws-ssm=1.51.0,@aws-cdk/cloud-assembly-schema=1.51.0,@aws-cdk/core=1.51.0,@aws-cdk/custom-resources=1.51.0,@aws-cdk/cx-api=1.51.0,@aws-cdk/region-info=1.51.0,jsii-runtime=node.js/v12.14.1
    Condition: CDKMetadataAvailable
Parameters:
Parameters:
  Term:
    Type: String
    Description: Searching Keyword
  MinDate:
    Type: String
    Description: Start Date e.g.YYYY/MM
  MaxDate:
    Type: String
    Description: End Date e.g.YYYY/MM
Conditions:
  CDKMetadataAvailable:
    Fn::Or:
      - Fn::Or:
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-east-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-northeast-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-northeast-2
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-southeast-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-southeast-2
          - Fn::Equals:
              - Ref: AWS::Region
              - ca-central-1
          - Fn::Equals:
              - Ref: AWS::Region
              - cn-north-1
          - Fn::Equals:
              - Ref: AWS::Region
              - cn-northwest-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-central-1
      - Fn::Or:
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-north-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-2
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-3
          - Fn::Equals:
              - Ref: AWS::Region
              - me-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - sa-east-1
          - Fn::Equals:
              - Ref: AWS::Region
              - us-east-1
          - Fn::Equals:
              - Ref: AWS::Region
              - us-east-2
          - Fn::Equals:
              - Ref: AWS::Region
              - us-west-1
          - Fn::Equals:
              - Ref: AWS::Region
              - us-west-2

