constructor()

in lib/cdk-emr-s3-trigger-stack.ts [35:78]


  constructor(scope: cdk.Construct, id: string, props: Props) {
    super(scope, id, props);
    const sourceBucket = new s3.Bucket(this, 'SourceBucket', {
      bucketName: props.sourceBucketName
    });
    const destinationBucket = new s3.Bucket(this, 'DestinationBucket', {
      bucketName: props.destinationBucketName
    });
    const jobBucket = new s3.Bucket(this, 'JobBucket', {
      bucketName: props.jobBucketName
    });
    new s3deployment.BucketDeployment(this, 'UploadSimpleSparkJob', {
      destinationBucket: jobBucket,
      sources: [s3deployment.Source.asset('demo/')]
    })
    
    const helloEmrFunction = new lambda.Function(this, 'HelloEmrFunction', {
      runtime: lambda.Runtime.PYTHON_3_8,
      handler: 'hello_emr.lambda_handler',
      code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')),
      environment: {
        DESTINATION_BUCKET_NAME: props.destinationBucketName,
        JOB_BUCKET_NAME: props.jobBucketName,
        JOB_FILE_NAME: props.jobFileName
      }
    });
    helloEmrFunction.addToRolePolicy(new iam.PolicyStatement({
      actions: [
        "elasticmapreduce:RunJobFlow"
      ],
      resources: ['*']
    }));
    helloEmrFunction.addToRolePolicy(new iam.PolicyStatement({
      actions: [
        "iam:PassRole"
      ],
      resources: [`arn:aws:iam::${this.account}:role/EMR_DefaultRole`,
                  `arn:aws:iam::${this.account}:role/EMR_EC2_DefaultRole`]
    }));

    helloEmrFunction.addEventSource(new S3EventSource(sourceBucket, {
      events: [s3.EventType.OBJECT_CREATED]
    }))
  }