data-yaml / vivos

Versioned Interoperability to Velocitize Open Science
Apache License 2.0
0 stars 0 forks source link

VivosQuilt #3

Closed drernie closed 9 months ago

drernie commented 9 months ago

Parameters

Actions

drernie commented 9 months ago

https://medium.com/event-driven-utopia/sending-and-receiving-custom-events-with-aws-eventbridge-schema-registry-b73198b7a140

The best option is to use EventBridge Schema Registry to discover, create, and manage schemas for the events used by both services.

https://github.com/dunithd/edu-samples/blob/main/aws-eventbridge-custom-events/email-service/template.yaml

      Events:
        OrderConfirmed:
          Type: CloudWatchEvent # More info about CloudWatchEvent Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cloudwatchevent
          Properties:
            EventBusName: custom-event-bus #Uncomment this if your events are not on the 'default' event bus
            Pattern:
              source:
                - edu.svc.orders
              detail-type:
                - Order Confirmed
drernie commented 9 months ago

Specifically:

When this S3 bucket creates or updates a file under s3://bucket/.quilt/named_packages/

  1. Send me an email
  2. Call Vivos
drernie commented 9 months ago
import { S3EventSource } from 'aws-cdk-lib/aws-lambda-event-sources'
import { Topic } from 'aws-cdk-lib/aws-sns'
import { EmailSubscription } from 'aws-cdk-lib/aws-sns-subscriptions'
import {
  AccountPrincipal,
  ManagedPolicy,
  PolicyStatement,
  Role,
  ServicePrincipal
} from 'aws-cdk-lib/aws-iam'

    // SNS Topic for failure notifications
    const topicName = `${APP_NAME}_workflow_status_topic`
    this.statusTopic = new Topic(this, topicName, {
      displayName: topicName,
      topicName: topicName
    })

    // Create an EventBridge rule that sends SNS notification on failure
    const ruleWorkflowStatusTopic = new Rule(
      this,
      `${APP_NAME}_rule_workflow_status_topic`,
      {
        eventPattern: {
          source: ['aws.omics'],
          detailType: ['Run Status Change'],
          detail: {
            status: ['FAILED', 'COMPLETED', 'CREATED']
          }
        }
      }
    )

    ruleWorkflowStatusTopic.addTarget(new SnsTopic(this.statusTopic))

    const servicePrincipal = new ServicePrincipal('events.amazonaws.com')
    this.statusTopic.grantPublish(servicePrincipal)
    this.statusTopic.grantPublish(this.principal) // for debugging purposes
    this.statusTopic.addSubscription(new EmailSubscription(props.email))
drernie commented 9 months ago
import {
  Bucket,
  BlockPublicAccess,
  EventType,
  BucketEncryption,
  BucketPolicy
} from 'aws-cdk-lib/aws-s3'

    const fastqWorkflowLambda = this.makeLambda('wf1_fastq', {})
    // Add S3 event source to Lambda
    fastqWorkflowLambda.addEventSource(
      new S3EventSource(this.inputBucket, {
        events: [EventType.OBJECT_CREATED],
        filters: [
          { prefix: this.manifest_prefix, suffix: this.manifest_suffix }
        ]
      })
    )