class Stream (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.Kinesis.Stream |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awskinesis#Stream |
Java | software.amazon.awscdk.services.kinesis.Stream |
Python | aws_cdk.aws_kinesis.Stream |
TypeScript (source) | aws-cdk-lib » aws_kinesis » Stream |
Implements
IConstruct
, IDependable
, IResource
, IStream
A Kinesis stream.
Can be encrypted with a KMS key.
Example
const key = new kms.Key(this, 'MyKey');
new kinesis.Stream(this, 'MyEncryptedStream', {
encryption: kinesis.StreamEncryption.KMS,
encryptionKey: key,
});
Initializer
new Stream(scope: Construct, id: string, props?: StreamProps)
Parameters
- scope
Construct
- id
string
- props
Stream
Props
Construct Props
Name | Type | Description |
---|---|---|
encryption? | Stream | The kind of server-side encryption to apply to this stream. |
encryption | IKey | External KMS key to use for stream encryption. |
removal | Removal | Policy to apply when the stream is removed from the stack. |
retention | Duration | The number of hours for the data records that are stored in shards to remain accessible. |
shard | number | The number of shards for the stream. |
stream | Stream | The capacity mode of this stream. |
stream | string | Enforces a particular physical stream name. |
encryption?
Type:
Stream
(optional, default: StreamEncryption.KMS if encrypted Streams are supported in the region
or StreamEncryption.UNENCRYPTED otherwise.
StreamEncryption.KMS if an encryption key is supplied through the encryptionKey property)
The kind of server-side encryption to apply to this stream.
If you choose KMS, you can specify a KMS key via encryptionKey
. If
encryption key is not specified, a key will automatically be created.
encryptionKey?
Type:
IKey
(optional, default: Kinesis Data Streams master key ('/alias/aws/kinesis').
If encryption is set to StreamEncryption.KMS and this property is undefined, a new KMS key
will be created and associated with this stream.)
External KMS key to use for stream encryption.
The 'encryption' property must be set to "Kms".
removalPolicy?
Type:
Removal
(optional, default: RemovalPolicy.RETAIN)
Policy to apply when the stream is removed from the stack.
retentionPeriod?
Type:
Duration
(optional, default: Duration.hours(24))
The number of hours for the data records that are stored in shards to remain accessible.
shardCount?
Type:
number
(optional, default: 1)
The number of shards for the stream.
Can only be provided if streamMode is Provisioned.
streamMode?
Type:
Stream
(optional, default: StreamMode.PROVISIONED)
The capacity mode of this stream.
streamName?
Type:
string
(optional, default:
Enforces a particular physical stream name.
Properties
Name | Type | Description |
---|---|---|
auto | boolean | Indicates if a stream resource policy should automatically be created upon the first call to addToResourcePolicy . |
env | Resource | The environment this resource belongs to. |
node | Node | The tree node. |
stack | Stack | The stack in which this resource is defined. |
stream | string | The ARN of the stream. |
stream | string | The name of the stream. |
encryption | IKey | Optional KMS encryption key associated with this stream. |
autoCreatePolicy
Type:
boolean
Indicates if a stream resource policy should automatically be created upon the first call to addToResourcePolicy
.
Set by subclasses.
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
node
Type:
Node
The tree node.
stack
Type:
Stack
The stack in which this resource is defined.
streamArn
Type:
string
The ARN of the stream.
streamName
Type:
string
The name of the stream.
encryptionKey?
Type:
IKey
(optional)
Optional KMS encryption key associated with this stream.
Methods
Name | Description |
---|---|
add | Adds a statement to the IAM resource policy associated with this stream. |
apply | Apply the given removal policy to this resource. |
grant(grantee, ...actions) | Grant the indicated permissions on this stream to the given IAM principal (Role/Group/User). |
grant | Grant read permissions for this stream and its contents to an IAM principal (Role/Group/User). |
grant | Grants read/write permissions for this stream and its contents to an IAM principal (Role/Group/User). |
grant | Grant write permissions for this stream and its contents to an IAM principal (Role/Group/User). |
metric(metricName, props?) | Return stream metric based from its metric name. |
metric | The number of records retrieved from the shard, measured over the specified time period. |
metric | The number of bytes retrieved from the Kinesis stream, measured over the specified time period. |
metric | The age of the last record in all GetRecords calls made against a Kinesis stream, measured over the specified time period. |
metric | The number of successful GetRecords operations per stream, measured over the specified time period. |
metric | The number of successful GetRecords operations per stream, measured over the specified time period. |
metric | The number of bytes successfully put to the Kinesis stream over the specified time period. |
metric | The number of records successfully put to the Kinesis stream over the specified time period. |
metric | The number of bytes put to the Kinesis stream using the PutRecord operation over the specified time period. |
metric | The time taken per PutRecord operation, measured over the specified time period. |
metric | The number of successful PutRecord operations per Kinesis stream, measured over the specified time period. |
metric | The number of bytes put to the Kinesis stream using the PutRecords operation over the specified time period. |
metric | The number of records rejected due to internal failures in a PutRecords operation per Kinesis data stream, measured over the specified time period. |
metric | The time taken per PutRecords operation, measured over the specified time period. |
metric | The number of PutRecords operations where at least one record succeeded, per Kinesis stream, measured over the specified time period. |
metric | The number of successful records in a PutRecords operation per Kinesis data stream, measured over the specified time period. |
metric | The number of records rejected due to throttling in a PutRecords operation per Kinesis data stream, measured over the specified time period. |
metric | The total number of records sent in a PutRecords operation per Kinesis data stream, measured over the specified time period. |
metric | The number of GetRecords calls throttled for the stream over the specified time period. |
metric | The number of records rejected due to throttling for the stream over the specified time period. |
to | Returns a string representation of this construct. |
static from | Import an existing Kinesis Stream provided an ARN. |
static from | Creates a Stream construct that represents an external stream. |
ToResourcePolicy(statement)
addpublic addToResourcePolicy(statement: PolicyStatement): AddToResourcePolicyResult
Parameters
- statement
Policy
Statement
Returns
Adds a statement to the IAM resource policy associated with this stream.
If this stream was created in this stack (new Strem
), a resource policy
will be automatically created upon the first call to addToResourcePolicy
. If
the stream is imported (Stream.import
), then this is a no-op.
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
grant(grantee, ...actions)
public grant(grantee: IGrantable, ...actions: string[]): Grant
Parameters
- grantee
IGrantable
- actions
string
Returns
Grant the indicated permissions on this stream to the given IAM principal (Role/Group/User).
Read(grantee)
grantpublic grantRead(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
Returns
Grant read permissions for this stream and its contents to an IAM principal (Role/Group/User).
If an encryption key is used, permission to ues the key to decrypt the contents of the stream will also be granted.
ReadWrite(grantee)
grantpublic grantReadWrite(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
Returns
Grants read/write permissions for this stream and its contents to an IAM principal (Role/Group/User).
If an encryption key is used, permission to use the key for encrypt/decrypt will also be granted.
Write(grantee)
grantpublic grantWrite(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
Returns
Grant write permissions for this stream and its contents to an IAM principal (Role/Group/User).
If an encryption key is used, permission to ues the key to encrypt the contents of the stream will also be granted.
metric(metricName, props?)
public metric(metricName: string, props?: MetricOptions): Metric
Parameters
- metricName
string
— name of the stream metric. - props
Metric
— properties of the metric.Options
Returns
Return stream metric based from its metric name.
GetRecords(props?)
metricpublic metricGetRecords(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The number of records retrieved from the shard, measured over the specified time period.
Minimum, Maximum, and Average statistics represent the records in a single GetRecords operation for the stream in the specified time period.
average
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
GetRecordsBytes(props?)
metricpublic metricGetRecordsBytes(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The number of bytes retrieved from the Kinesis stream, measured over the specified time period.
Minimum, Maximum, and Average statistics represent the bytes in a single GetRecords operation for the stream in the specified time period.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
GetRecordsIteratorAgeMilliseconds(props?)
metricpublic metricGetRecordsIteratorAgeMilliseconds(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The age of the last record in all GetRecords calls made against a Kinesis stream, measured over the specified time period.
Age is the difference between the current time and when the last record of the GetRecords call was written to the stream. The Minimum and Maximum statistics can be used to track the progress of Kinesis consumer applications. A value of zero indicates that the records being read are completely caught up with the stream.
The metric defaults to maximum over 5 minutes, it can be changed by passing statistic
and period
properties.
GetRecordsLatency(props?)
metricpublic metricGetRecordsLatency(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The number of successful GetRecords operations per stream, measured over the specified time period.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
GetRecordsSuccess(props?)
metricpublic metricGetRecordsSuccess(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The number of successful GetRecords operations per stream, measured over the specified time period.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
IncomingBytes(props?)
metricpublic metricIncomingBytes(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The number of bytes successfully put to the Kinesis stream over the specified time period.
This metric includes bytes from PutRecord and PutRecords operations. Minimum, Maximum, and Average statistics represent the bytes in a single put operation for the stream in the specified time period.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
IncomingRecords(props?)
metricpublic metricIncomingRecords(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The number of records successfully put to the Kinesis stream over the specified time period.
This metric includes record counts from PutRecord and PutRecords operations. Minimum, Maximum, and Average statistics represent the records in a single put operation for the stream in the specified time period.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
PutRecordBytes(props?)
metricpublic metricPutRecordBytes(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The number of bytes put to the Kinesis stream using the PutRecord operation over the specified time period.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
PutRecordLatency(props?)
metricpublic metricPutRecordLatency(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The time taken per PutRecord operation, measured over the specified time period.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
PutRecordSuccess(props?)
metricpublic metricPutRecordSuccess(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The number of successful PutRecord operations per Kinesis stream, measured over the specified time period.
Average reflects the percentage of successful writes to a stream.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
PutRecordsBytes(props?)
metricpublic metricPutRecordsBytes(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The number of bytes put to the Kinesis stream using the PutRecords operation over the specified time period.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
PutRecordsFailedRecords(props?)
metricpublic metricPutRecordsFailedRecords(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The number of records rejected due to internal failures in a PutRecords operation per Kinesis data stream, measured over the specified time period.
Occasional internal failures are to be expected and should be retried.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
PutRecordsLatency(props?)
metricpublic metricPutRecordsLatency(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The time taken per PutRecords operation, measured over the specified time period.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
PutRecordsSuccess(props?)
metricpublic metricPutRecordsSuccess(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The number of PutRecords operations where at least one record succeeded, per Kinesis stream, measured over the specified time period.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
PutRecordsSuccessfulRecords(props?)
metricpublic metricPutRecordsSuccessfulRecords(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The number of successful records in a PutRecords operation per Kinesis data stream, measured over the specified time period.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
PutRecordsThrottledRecords(props?)
metricpublic metricPutRecordsThrottledRecords(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The number of records rejected due to throttling in a PutRecords operation per Kinesis data stream, measured over the specified time period.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
PutRecordsTotalRecords(props?)
metricpublic metricPutRecordsTotalRecords(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The total number of records sent in a PutRecords operation per Kinesis data stream, measured over the specified time period.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
ReadProvisionedThroughputExceeded(props?)
metricpublic metricReadProvisionedThroughputExceeded(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The number of GetRecords calls throttled for the stream over the specified time period.
The most commonly used statistic for this metric is Average.
When the Minimum statistic has a value of 1, all records were throttled for the stream during the specified time period.
When the Maximum statistic has a value of 0 (zero), no records were throttled for the stream during the specified time period.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties
WriteProvisionedThroughputExceeded(props?)
metricpublic metricWriteProvisionedThroughputExceeded(props?: MetricOptions): Metric
Parameters
- props
Metric
— properties of the metric.Options
Returns
The number of records rejected due to throttling for the stream over the specified time period.
This metric includes throttling from PutRecord and PutRecords operations.
When the Minimum statistic has a non-zero value, records were being throttled for the stream during the specified time period.
When the Maximum statistic has a value of 0 (zero), no records were being throttled for the stream during the specified time period.
The metric defaults to average over 5 minutes, it can be changed by passing statistic
and period
properties.
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
StreamArn(scope, id, streamArn)
static frompublic static fromStreamArn(scope: Construct, id: string, streamArn: string): IStream
Parameters
- scope
Construct
— The parent creating construct (usuallythis
). - id
string
— The construct's name. - streamArn
string
— Stream ARN (i.e. arn:aws:kinesis::<account-id>:stream/Foo).
Returns
Import an existing Kinesis Stream provided an ARN.
StreamAttributes(scope, id, attrs)
static frompublic static fromStreamAttributes(scope: Construct, id: string, attrs: StreamAttributes): IStream
Parameters
- scope
Construct
— The parent creating construct (usuallythis
). - id
string
— The construct's name. - attrs
Stream
— Stream import properties.Attributes
Returns
Creates a Stream construct that represents an external stream.