constructor()

in transcribe-ui-backend/provisioning/lib/construct/events.ts [16:59]


  constructor(scope: cdk.Construct, id: string, props: EventProps) {
    super(scope, id)

    const fromAddress: string = scope.node.tryGetContext('fromAddress')
    if (!(fromAddress || '').trim()) {
      throw new Error('fromAddress not found')
    }

    const sendmailFunc = new LambdaFunction(this, `${id}-sendmail`, {
      entry: './lambda/sendmail.ts',
      environment: {
        JOB_TABLE: props.jobTable.tableName,
        TRANSCRIBE_BUCKET: props.transBucket.bucketName,
        FROM_ADDRESS: fromAddress
      },
      modules: ['iconv-lite']
    })
    sendmailFunc.role!.addToPrincipalPolicy(
      new iam.PolicyStatement({
        effect: iam.Effect.ALLOW,
        resources: ['*'],
        actions: [
          'transcribe:GetTranscriptionJob',
          'transcribe:DeleteTranscriptionJob',
          'ses:SendEmail',
          'ses:SendRawEmail'
        ]
      })
    )
    props.jobTable.grantReadWriteData(sendmailFunc)
    props.transBucket.grantReadWrite(sendmailFunc)

    const rule = new events.Rule(this, `${id}-trans-event-rule`, {
      eventPattern: {
        source: ['aws.transcribe'],
        detailType: ['Transcribe Job State Change'],
        detail: {
          TranscriptionJobStatus: ['COMPLETED', 'FAILED']
        }
      }
    })

    rule.addTarget(new eventsTargets.LambdaFunction(sendmailFunc))
  }