Skip to content

Latest commit

 

History

History
257 lines (158 loc) · 10.1 KB

File metadata and controls

257 lines (158 loc) · 10.1 KB

S3BucketsUsageMetricPublisher

A construct that creates an AWS Lambda function to publish S3 General Purpose buckets usage metrics to CloudWatch.

Usage

To use the S3BucketsUsageMetricPublisher construct, simply import it into your AWS CDK stack and create a new instance of the construct:

import { Stack } from 'aws-cdk-lib';
import { S3BucketsUsageMetricPublisher } from './s3-buckets-usage-metric-publisher';

const stack = new Stack(app, 'MyStack');

new S3BucketsUsageMetricPublisher(stack, 'MyS3BucketsUsageMetricPublisher', {
  publishFrequency: 5,
  cwNamespace: 'MyNamespace',
});

This will create a new AWS Lambda function that publishes the number of S3 bucket to CloudWatch every 5 minutes for the us-east-1 and us-west-2 regions, using the MyNamespace namespace.

API

S3BucketsUsageMetricPublisher(scope: Construct, id: string, props: S3BucketsUsageMetricPublisherProps)

Creates a new instance of the S3BucketsUsageMetricPublisher construct.

Parameters

  • scope - The parent construct.
  • id - The ID of the construct.
  • props - The properties of the construct.

Properties

  • publishFrequency - The time interval (in minutes) that the Lambda function will be triggered to publish metrics to CloudWatch.
  • handler - The AWS Lambda function that publishes usage metrics to CloudWatch.
  • rule - The CloudWatch Events rule that triggers the Lambda function to publish metrics to CloudWatch.
  • cwNamespace - The CloudWatch namespace to publish metrics to.

License

This library is licensed under the Apache 2.0 License. See the LICENSE file.

API Reference

Constructs

S3BucketsUsageMetricPublisher

A construct that creates an AWS Lambda function to publish S3 general purpose usage metrics to CloudWatch.

Initializers

import { S3BucketsUsageMetricPublisher } from '@time-loop/cdk-s3-buckets-usage-metric-publisher'

new S3BucketsUsageMetricPublisher(scope: Construct, id: Namer, props: S3BucketsUsageMetricPublisherProps)
Name Type Description
scope constructs.Construct The parent construct.
id multi-convention-namer.Namer The ID of the construct.
props S3BucketsUsageMetricPublisherProps The properties of the construct.

scopeRequired
  • Type: constructs.Construct

The parent construct.


idRequired
  • Type: multi-convention-namer.Namer

The ID of the construct.


propsRequired

The properties of the construct.


Methods

Name Description
toString Returns a string representation of this construct.

toString
public toString(): string

Returns a string representation of this construct.

Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
import { S3BucketsUsageMetricPublisher } from '@time-loop/cdk-s3-buckets-usage-metric-publisher'

S3BucketsUsageMetricPublisher.isConstruct(x: any)

Checks if x is a construct.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.
cwNamespace string No description.
handler aws-cdk-lib.aws_lambda_nodejs.NodejsFunction No description.
publishFrequency number No description.
rule aws-cdk-lib.aws_events.Rule No description.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


cwNamespaceRequired
public readonly cwNamespace: string;
  • Type: string

handlerRequired
public readonly handler: NodejsFunction;
  • Type: aws-cdk-lib.aws_lambda_nodejs.NodejsFunction

publishFrequencyRequired
public readonly publishFrequency: number;
  • Type: number

ruleRequired
public readonly rule: Rule;
  • Type: aws-cdk-lib.aws_events.Rule

Structs

S3BucketsUsageMetricPublisherProps

Initializer

import { S3BucketsUsageMetricPublisherProps } from '@time-loop/cdk-s3-buckets-usage-metric-publisher'

const s3BucketsUsageMetricPublisherProps: S3BucketsUsageMetricPublisherProps = { ... }

Properties

Name Type Description
cloudwatchLogsRetention aws-cdk-lib.aws_logs.RetentionDays How long to retain logs published to CloudWatch logs.
cwNamespace string The CloudWatch namespace to publish metrics to.
publishFrequency number Time intervals that Lambda will be triggered to publish metric in CloudWatch.

cloudwatchLogsRetentionOptional
public readonly cloudwatchLogsRetention: RetentionDays;
  • Type: aws-cdk-lib.aws_logs.RetentionDays
  • Default: aws_logs.RetentionDays.THREE_MONTHS

How long to retain logs published to CloudWatch logs.


cwNamespaceOptional
public readonly cwNamespace: string;
  • Type: string
  • Default: 'S3GeneralPurposeBucketsUsage'

The CloudWatch namespace to publish metrics to.


publishFrequencyOptional
public readonly publishFrequency: number;
  • Type: number
  • Default: 1

Time intervals that Lambda will be triggered to publish metric in CloudWatch.