How to use the @aws-cdk/core.Duration function in @aws-cdk/core

To help you get started, we’ve selected a few @aws-cdk/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github deepalert / deepalert / lib / deepalert-stack.ts View on Github external
// ----------------------------------------------------------------
    // Messaging Channels
    this.alertTopic = new sns.Topic(this, "alertTopic");
    this.taskTopic = new sns.Topic(this, "taskTopic");
    this.contentTopic = new sns.Topic(this, "contentTopic");
    this.attributeTopic = new sns.Topic(this, "attributeTopic");
    this.reportTopic = new sns.Topic(this, "reportTopic");

    const alertQueueTimeout = cdk.Duration.seconds(30);
    this.alertQueue = new sqs.Queue(this, "alertQueue", {
      visibilityTimeout: alertQueueTimeout,
    });
    this.alertTopic.addSubscription(new SqsSubscription(this.alertQueue));

    const contentQueueTimeout = cdk.Duration.seconds(30);
    this.contentQueue = new sqs.Queue(this, "contentQueue", {
      visibilityTimeout: contentQueueTimeout,
    });

    const attributeQueueTimeout = cdk.Duration.seconds(30);
    this.attributeQueue = new sqs.Queue(this, "attributeQueue", {
      visibilityTimeout: attributeQueueTimeout,
    });

    // ----------------------------------------------------------------
    // Lambda Functions
    const baseEnvVars = {
      TASK_TOPIC: this.taskTopic.topicArn,
      REPORT_TOPIC: this.reportTopic.topicArn,
      CACHE_TABLE: this.cacheTable.tableName,
    };
github aws / aws-cdk / packages / @aws-cdk / aws-appmesh / lib / virtual-node.ts View on Github external
function renderHealthCheck(hc: HealthCheck | undefined, pm: PortMapping): CfnVirtualNode.HealthCheckProperty | undefined {
  if (hc === undefined) { return undefined; }

  if (hc.protocol === Protocol.TCP && hc.path) {
    throw new Error('The path property cannot be set with Protocol.TCP');
  }

  const healthCheck: CfnVirtualNode.HealthCheckProperty = {
    healthyThreshold: hc.healthyThreshold || 2,
    intervalMillis: (hc.interval || cdk.Duration.seconds(5)).toMilliseconds(), // min
    path: hc.path || (hc.protocol === Protocol.HTTP ? '/' : undefined),
    port: hc.port || pm.port,
    protocol: hc.protocol || pm.protocol,
    timeoutMillis: (hc.timeout || cdk.Duration.seconds(2)).toMilliseconds(),
    unhealthyThreshold: hc.unhealthyThreshold || 2,
  };

  (Object.keys(healthCheck) as Array)
    .filter((key) =>
        HEALTH_CHECK_PROPERTY_THRESHOLDS[key] &&
          typeof healthCheck[key] === 'number' &&
          !cdk.Token.isUnresolved(healthCheck[key])
    ).map((key) => {
      const [min, max] = HEALTH_CHECK_PROPERTY_THRESHOLDS[key]!;
      const value = healthCheck[key]!;
github deepalert / deepalert / lib / deepalert-stack.ts View on Github external
this.cacheTable = new dynamodb.Table(this, "cacheTable", {
      billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
      partitionKey: { name: "pk", type: dynamodb.AttributeType.STRING },
      sortKey: { name: "sk", type: dynamodb.AttributeType.STRING },
      timeToLiveAttribute: "expires_at",
    });

    // ----------------------------------------------------------------
    // Messaging Channels
    this.alertTopic = new sns.Topic(this, "alertTopic");
    this.taskTopic = new sns.Topic(this, "taskTopic");
    this.contentTopic = new sns.Topic(this, "contentTopic");
    this.attributeTopic = new sns.Topic(this, "attributeTopic");
    this.reportTopic = new sns.Topic(this, "reportTopic");

    const alertQueueTimeout = cdk.Duration.seconds(30);
    this.alertQueue = new sqs.Queue(this, "alertQueue", {
      visibilityTimeout: alertQueueTimeout,
    });
    this.alertTopic.addSubscription(new SqsSubscription(this.alertQueue));

    const contentQueueTimeout = cdk.Duration.seconds(30);
    this.contentQueue = new sqs.Queue(this, "contentQueue", {
      visibilityTimeout: contentQueueTimeout,
    });

    const attributeQueueTimeout = cdk.Duration.seconds(30);
    this.attributeQueue = new sqs.Queue(this, "attributeQueue", {
      visibilityTimeout: attributeQueueTimeout,
    });

    // ----------------------------------------------------------------
github aws / aws-cdk / packages / @aws-cdk / aws-cloudwatch / lib / metric.ts View on Github external
constructor(props: MetricProps) {
    this.period = props.period || cdk.Duration.minutes(5);
    const periodSec = this.period.toSeconds();
    if (periodSec !== 1 && periodSec !== 5 && periodSec !== 10 && periodSec !== 30 && periodSec % 60 !== 0) {
      throw new Error(`'period' must be 1, 5, 10, 30, or a multiple of 60 seconds, received ${props.period}`);
    }

    this.dimensions = props.dimensions;
    this.namespace = props.namespace;
    this.metricName = props.metricName;
    // Try parsing, this will throw if it's not a valid stat
    this.statistic = normalizeStatistic(props.statistic || "Average");
    this.label = props.label;
    this.color = props.color;
    this.unit = props.unit;
  }
github aws / aws-cdk / packages / @aws-cdk / aws-ecs / lib / drain-hook / instance-drain-hook.ts View on Github external
constructor(scope: cdk.Construct, id: string, props: InstanceDrainHookProps) {
    super(scope, id);

    const drainTime = props.drainTime || cdk.Duration.minutes(5);

    // Invoke Lambda via SNS Topic
    const fn = new lambda.Function(this, 'Function', {
      code: lambda.Code.fromInline(fs.readFileSync(path.join(__dirname, 'lambda-source', 'index.py'), { encoding: 'utf-8' })),
      handler: 'index.lambda_handler',
      runtime: lambda.Runtime.PYTHON_3_6,
      // Timeout: some extra margin for additional API calls made by the Lambda,
      // up to a maximum of 15 minutes.
      timeout: cdk.Duration.seconds(Math.min(drainTime.toSeconds() + 10, 900)),
      environment: {
        CLUSTER: props.cluster.clusterName
      }
    });

    // Hook everything up: ASG -> Topic, Topic -> Lambda
    props.autoScalingGroup.addLifecycleHook('DrainHook', {
github aws-samples / aws-serverless-workshop-greater-china-region / Lab4-WildRyde-WebApplication / deploy / lib / lab4-stack.ts View on Github external
const lambdaRole = new iam.Role(this, `WildRydes-Lambda-Role`, {
      assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
      managedPolicies: [
        iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole'),
      ]
    });
    // allow lambda role to write data to given table
    ridesTable.grantWriteData(lambdaRole);

    const wildRydesLambda = new lambda.Function(this, `WildRydesLambda`, {
      runtime: lambda.Runtime.NODEJS_12_X,
      role: lambdaRole,
      code: lambda.Code.fromAsset(path.join(__dirname, '../dist/lambda/')),
      handler: 'index.handler',
      timeout: cdk.Duration.seconds(29),
    });

    // part 3 -- backend integrate with API Gateway
    const api = new apigateway.RestApi(this, 'WildRydesAPI', {
      deployOptions: {
          stageName: 'prod',
      },
      endpointConfiguration: {
        types: [ apigateway.EndpointType.REGIONAL ]
      }
    });
    const rideRes = api.root.addResource('ride');
    rideRes.addCorsPreflight({
      allowOrigins: apigateway.Cors.ALL_ORIGINS,
    });
github aws-samples / aws-cdk-changelogs-demo / changelogs-md.js View on Github external
runtime: lambda.Runtime.NODEJS_10_X,
      handler: 'recently-crawled.handle',
      code: lambda.Code.asset('./app/recently-crawled'),
      environment: {
        FEEDS_TABLE_NAME: props.feedsTable.tableName,
        API_BUCKET_NAME: props.apiBucket.bucketName
      }
    });

    // Grant the lambda permission to modify the tables and S3 bucket
    props.feedsTable.grantReadWriteData(recentlyCrawled.role);
    props.apiBucket.grantReadWrite(recentlyCrawled.role);

    // Schedule the recrawler to run once every minute
    this.eventRule = new events.Rule(this, 'recrawl-check-schedule', {
      schedule: events.Schedule.rate(cdk.Duration.minutes(1)),
      targets: [
        new targets.LambdaFunction(recentlyCrawled)
      ]
    });
  }
}
github deepalert / deepalert / test / workflow / bin / stack.ts View on Github external
constructor(scope: cdk.Construct, id: string, props: properties) {
    super(scope, id, props);

    const table = new dynamodb.Table(this, "resultTable", {
      billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
      partitionKey: { name: "pk", type: dynamodb.AttributeType.STRING },
      sortKey: { name: "sk", type: dynamodb.AttributeType.STRING },
    });

    const buildPath = lambda.Code.fromAsset("./build");

    const testInspector = new lambda.Function(this, "testInspector", {
      runtime: lambda.Runtime.GO_1_X,
      handler: "inspector",
      timeout: cdk.Duration.seconds(30),
      code: buildPath,
      events: [new SnsEventSource(props.deepalert.taskTopic)],
      environment: {
        RESULT_TABLE: table.tableName,
        FINDING_QUEUE: props.deepalert.findingQueue.queueUrl,
        ATTRIBUTE_QUEUE: props.deepalert.attributeQueue.queueUrl,
      },
    });

    const testEmitter = new lambda.Function(this, "testEmitter", {
      runtime: lambda.Runtime.GO_1_X,
      handler: "emitter",
      timeout: cdk.Duration.seconds(30),
      code: buildPath,
      events: [new SnsEventSource(props.deepalert.reportTopic)],
      environment: {
github fogfish / aws-cdk-pure / hoc / src / staticweb.ts View on Github external
aliasConfiguration: {
      acmCertRef,
      names: [ site(props) ],
      securityPolicy: cdn.SecurityPolicyProtocol.TLS_V1_2_2018,
      sslMethod: cdn.SSLMethod.SNI,
    },
    httpVersion: cdn.HttpVersion.HTTP1_1,
    originConfigs: [
      {
        behaviors : [
          {
            defaultTtl: cdk.Duration.hours(24),
            forwardedValues: {queryString: true},
            isDefaultBehavior: true,
            maxTtl: cdk.Duration.hours(24),
            minTtl: cdk.Duration.seconds(0),
          }
        ],
        originPath: (!props.sites || props.sites.length === 0) ? '/' : props.sites[0].origin,
        s3OriginSource: {
          s3BucketSource
        },
      }
    ]
  })
  return iaac(SiteCDN)
github fogfish / aws-cdk-pure / hoc / src / gateway.ts View on Github external
const ApiDNS  = (): dns.ARecordProps => ({
    recordName: site(props),
    target: {aliasTarget: new target.ApiGateway(restapi)},
    ttl: cdk.Duration.seconds(60),
    zone,
  })
  return iaac(ApiDNS)