# Amazon Managed Streaming for Apache Kafka Construct Library
<!--BEGIN STABILITY BANNER-->---
![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge)
> The APIs of higher level constructs in this module are experimental and under active development.
> They are subject to non-backward compatible changes or removal in any future version. These are
> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be
> announced in the release notes. This means that while you may use them, you may need to update
> your source code when upgrading to a newer version of this package.
---
<!--END STABILITY BANNER-->
[Amazon MSK](https://aws.amazon.com/msk/) is a fully managed service that makes it easy for you to build and run applications that use Apache Kafka to process streaming data.
The following example creates an MSK Cluster.
```python
# vpc: ec2.Vpc
cluster = msk.Cluster(self, "Cluster",
cluster_name="myCluster",
kafka_version=msk.KafkaVersion.V2_8_1,
vpc=vpc
)
```
## Allowing Connections
To control who can access the Cluster, use the `.connections` attribute. For a list of ports used by MSK, refer to the [MSK documentation](https://docs.aws.amazon.com/msk/latest/developerguide/client-access.html#port-info).
```python
# vpc: ec2.Vpc
cluster = msk.Cluster(self, "Cluster",
cluster_name="myCluster",
kafka_version=msk.KafkaVersion.V2_8_1,
vpc=vpc
)
cluster.connections.allow_from(
ec2.Peer.ipv4("1.2.3.4/8"),
ec2.Port.tcp(2181))
cluster.connections.allow_from(
ec2.Peer.ipv4("1.2.3.4/8"),
ec2.Port.tcp(9094))
```
## Cluster Endpoints
You can use the following attributes to get a list of the Kafka broker or ZooKeeper node endpoints
```python
# cluster: msk.Cluster
CfnOutput(self, "BootstrapBrokers", value=cluster.bootstrap_brokers)
CfnOutput(self, "BootstrapBrokersTls", value=cluster.bootstrap_brokers_tls)
CfnOutput(self, "BootstrapBrokersSaslScram", value=cluster.bootstrap_brokers_sasl_scram)
CfnOutput(self, "BootstrapBrokerStringSaslIam", value=cluster.bootstrap_brokers_sasl_iam)
CfnOutput(self, "ZookeeperConnection", value=cluster.zookeeper_connection_string)
CfnOutput(self, "ZookeeperConnectionTls", value=cluster.zookeeper_connection_string_tls)
```
## Importing an existing Cluster
To import an existing MSK cluster into your CDK app use the `.fromClusterArn()` method.
```python
cluster = msk.Cluster.from_cluster_arn(self, "Cluster", "arn:aws:kafka:us-west-2:1234567890:cluster/a-cluster/11111111-1111-1111-1111-111111111111-1")
```
## Client Authentication
[MSK supports](https://docs.aws.amazon.com/msk/latest/developerguide/kafka_apis_iam.html) the following authentication mechanisms.
### TLS
To enable client authentication with TLS set the `certificateAuthorityArns` property to reference your ACM Private CA. [More info on Private CAs.](https://docs.aws.amazon.com/msk/latest/developerguide/msk-authentication.html)
```python
import aws_cdk.aws_acmpca as acmpca
# vpc: ec2.Vpc
cluster = msk.Cluster(self, "Cluster",
cluster_name="myCluster",
kafka_version=msk.KafkaVersion.V2_8_1,
vpc=vpc,
encryption_in_transit=msk.EncryptionInTransitConfig(
client_broker=msk.ClientBrokerEncryption.TLS
),
client_authentication=msk.ClientAuthentication.tls(
certificate_authorities=[
acmpca.CertificateAuthority.from_certificate_authority_arn(self, "CertificateAuthority", "arn:aws:acm-pca:us-west-2:1234567890:certificate-authority/11111111-1111-1111-1111-111111111111")
]
)
)
```
### SASL/SCRAM
Enable client authentication with [SASL/SCRAM](https://docs.aws.amazon.com/msk/latest/developerguide/msk-password.html):
```python
# vpc: ec2.Vpc
cluster = msk.Cluster(self, "cluster",
cluster_name="myCluster",
kafka_version=msk.KafkaVersion.V2_8_1,
vpc=vpc,
encryption_in_transit=msk.EncryptionInTransitConfig(
client_broker=msk.ClientBrokerEncryption.TLS
),
client_authentication=msk.ClientAuthentication.sasl(
scram=True
)
)
```
### SASL/IAM
Enable client authentication with [IAM](https://docs.aws.amazon.com/msk/latest/developerguide/iam-access-control.html):
```python
# vpc: ec2.Vpc
cluster = msk.Cluster(self, "cluster",
cluster_name="myCluster",
kafka_version=msk.KafkaVersion.V2_8_1,
vpc=vpc,
encryption_in_transit=msk.EncryptionInTransitConfig(
client_broker=msk.ClientBrokerEncryption.TLS
),
client_authentication=msk.ClientAuthentication.sasl(
iam=True
)
)
```
### SASL/IAM + TLS
Enable client authentication with [IAM](https://docs.aws.amazon.com/msk/latest/developerguide/iam-access-control.html)
as well as enable client authentication with TLS by setting the `certificateAuthorityArns` property to reference your ACM Private CA. [More info on Private CAs.](https://docs.aws.amazon.com/msk/latest/developerguide/msk-authentication.html)
```python
import aws_cdk.aws_acmpca as acmpca
# vpc: ec2.Vpc
cluster = msk.Cluster(self, "Cluster",
cluster_name="myCluster",
kafka_version=msk.KafkaVersion.V2_8_1,
vpc=vpc,
encryption_in_transit=msk.EncryptionInTransitConfig(
client_broker=msk.ClientBrokerEncryption.TLS
),
client_authentication=msk.ClientAuthentication.sasl_tls(
iam=True,
certificate_authorities=[
acmpca.CertificateAuthority.from_certificate_authority_arn(self, "CertificateAuthority", "arn:aws:acm-pca:us-west-2:1234567890:certificate-authority/11111111-1111-1111-1111-111111111111")
]
)
)
```
## Logging
You can deliver Apache Kafka broker logs to one or more of the following destination types:
Amazon CloudWatch Logs, Amazon S3, Amazon Kinesis Data Firehose.
To configure logs to be sent to an S3 bucket, provide a bucket in the `logging` config.
```python
# vpc: ec2.Vpc
# bucket: s3.IBucket
cluster = msk.Cluster(self, "cluster",
cluster_name="myCluster",
kafka_version=msk.KafkaVersion.V2_8_1,
vpc=vpc,
logging=msk.BrokerLogging(
s3=msk.S3LoggingConfiguration(
bucket=bucket
)
)
)
```
When the S3 destination is configured, AWS will automatically create an S3 bucket policy
that allows the service to write logs to the bucket. This makes it impossible to later update
that bucket policy. To have CDK create the bucket policy so that future updates can be made,
the `@aws-cdk/aws-s3:createDefaultLoggingPolicy` [feature flag](https://docs.aws.amazon.com/cdk/v2/guide/featureflags.html) can be used. This can be set
in the `cdk.json` file.
```json
{
"context": {
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true
}
}
```
## Storage Mode
You can configure an MSK cluster storage mode using the `storageMode` property.
Tiered storage is a low-cost storage tier for Amazon MSK that scales to virtually unlimited storage,
making it cost-effective to build streaming data applications.
> Visit [Tiered storage](https://docs.aws.amazon.com/msk/latest/developerguide/msk-tiered-storage.html)
> to see the list of compatible Kafka versions and for more details.
```python
# vpc: ec2.Vpc
# bucket: s3.IBucket
cluster = msk.Cluster(self, "cluster",
cluster_name="myCluster",
kafka_version=msk.KafkaVersion.V3_6_0,
vpc=vpc,
storage_mode=msk.StorageMode.TIERED
)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/aws/aws-cdk",
"name": "aws-cdk.aws-msk-alpha",
"maintainer": null,
"docs_url": null,
"requires_python": "~=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Amazon Web Services",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/d9/07/1cf8b87b75ea86dbd2ac826c5659275a6fe174c8c64ae74fa1ab6937238a/aws_cdk_aws_msk_alpha-2.170.0a0.tar.gz",
"platform": null,
"description": "# Amazon Managed Streaming for Apache Kafka Construct Library\n\n<!--BEGIN STABILITY BANNER-->---\n\n\n![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge)\n\n> The APIs of higher level constructs in this module are experimental and under active development.\n> They are subject to non-backward compatible changes or removal in any future version. These are\n> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be\n> announced in the release notes. This means that while you may use them, you may need to update\n> your source code when upgrading to a newer version of this package.\n\n---\n<!--END STABILITY BANNER-->\n\n[Amazon MSK](https://aws.amazon.com/msk/) is a fully managed service that makes it easy for you to build and run applications that use Apache Kafka to process streaming data.\n\nThe following example creates an MSK Cluster.\n\n```python\n# vpc: ec2.Vpc\n\ncluster = msk.Cluster(self, \"Cluster\",\n cluster_name=\"myCluster\",\n kafka_version=msk.KafkaVersion.V2_8_1,\n vpc=vpc\n)\n```\n\n## Allowing Connections\n\nTo control who can access the Cluster, use the `.connections` attribute. For a list of ports used by MSK, refer to the [MSK documentation](https://docs.aws.amazon.com/msk/latest/developerguide/client-access.html#port-info).\n\n```python\n# vpc: ec2.Vpc\n\ncluster = msk.Cluster(self, \"Cluster\",\n cluster_name=\"myCluster\",\n kafka_version=msk.KafkaVersion.V2_8_1,\n vpc=vpc\n)\n\ncluster.connections.allow_from(\n ec2.Peer.ipv4(\"1.2.3.4/8\"),\n ec2.Port.tcp(2181))\ncluster.connections.allow_from(\n ec2.Peer.ipv4(\"1.2.3.4/8\"),\n ec2.Port.tcp(9094))\n```\n\n## Cluster Endpoints\n\nYou can use the following attributes to get a list of the Kafka broker or ZooKeeper node endpoints\n\n```python\n# cluster: msk.Cluster\n\nCfnOutput(self, \"BootstrapBrokers\", value=cluster.bootstrap_brokers)\nCfnOutput(self, \"BootstrapBrokersTls\", value=cluster.bootstrap_brokers_tls)\nCfnOutput(self, \"BootstrapBrokersSaslScram\", value=cluster.bootstrap_brokers_sasl_scram)\nCfnOutput(self, \"BootstrapBrokerStringSaslIam\", value=cluster.bootstrap_brokers_sasl_iam)\nCfnOutput(self, \"ZookeeperConnection\", value=cluster.zookeeper_connection_string)\nCfnOutput(self, \"ZookeeperConnectionTls\", value=cluster.zookeeper_connection_string_tls)\n```\n\n## Importing an existing Cluster\n\nTo import an existing MSK cluster into your CDK app use the `.fromClusterArn()` method.\n\n```python\ncluster = msk.Cluster.from_cluster_arn(self, \"Cluster\", \"arn:aws:kafka:us-west-2:1234567890:cluster/a-cluster/11111111-1111-1111-1111-111111111111-1\")\n```\n\n## Client Authentication\n\n[MSK supports](https://docs.aws.amazon.com/msk/latest/developerguide/kafka_apis_iam.html) the following authentication mechanisms.\n\n### TLS\n\nTo enable client authentication with TLS set the `certificateAuthorityArns` property to reference your ACM Private CA. [More info on Private CAs.](https://docs.aws.amazon.com/msk/latest/developerguide/msk-authentication.html)\n\n```python\nimport aws_cdk.aws_acmpca as acmpca\n\n# vpc: ec2.Vpc\n\ncluster = msk.Cluster(self, \"Cluster\",\n cluster_name=\"myCluster\",\n kafka_version=msk.KafkaVersion.V2_8_1,\n vpc=vpc,\n encryption_in_transit=msk.EncryptionInTransitConfig(\n client_broker=msk.ClientBrokerEncryption.TLS\n ),\n client_authentication=msk.ClientAuthentication.tls(\n certificate_authorities=[\n acmpca.CertificateAuthority.from_certificate_authority_arn(self, \"CertificateAuthority\", \"arn:aws:acm-pca:us-west-2:1234567890:certificate-authority/11111111-1111-1111-1111-111111111111\")\n ]\n )\n)\n```\n\n### SASL/SCRAM\n\nEnable client authentication with [SASL/SCRAM](https://docs.aws.amazon.com/msk/latest/developerguide/msk-password.html):\n\n```python\n# vpc: ec2.Vpc\n\ncluster = msk.Cluster(self, \"cluster\",\n cluster_name=\"myCluster\",\n kafka_version=msk.KafkaVersion.V2_8_1,\n vpc=vpc,\n encryption_in_transit=msk.EncryptionInTransitConfig(\n client_broker=msk.ClientBrokerEncryption.TLS\n ),\n client_authentication=msk.ClientAuthentication.sasl(\n scram=True\n )\n)\n```\n\n### SASL/IAM\n\nEnable client authentication with [IAM](https://docs.aws.amazon.com/msk/latest/developerguide/iam-access-control.html):\n\n```python\n# vpc: ec2.Vpc\n\ncluster = msk.Cluster(self, \"cluster\",\n cluster_name=\"myCluster\",\n kafka_version=msk.KafkaVersion.V2_8_1,\n vpc=vpc,\n encryption_in_transit=msk.EncryptionInTransitConfig(\n client_broker=msk.ClientBrokerEncryption.TLS\n ),\n client_authentication=msk.ClientAuthentication.sasl(\n iam=True\n )\n)\n```\n\n### SASL/IAM + TLS\n\nEnable client authentication with [IAM](https://docs.aws.amazon.com/msk/latest/developerguide/iam-access-control.html)\nas well as enable client authentication with TLS by setting the `certificateAuthorityArns` property to reference your ACM Private CA. [More info on Private CAs.](https://docs.aws.amazon.com/msk/latest/developerguide/msk-authentication.html)\n\n```python\nimport aws_cdk.aws_acmpca as acmpca\n\n# vpc: ec2.Vpc\n\ncluster = msk.Cluster(self, \"Cluster\",\n cluster_name=\"myCluster\",\n kafka_version=msk.KafkaVersion.V2_8_1,\n vpc=vpc,\n encryption_in_transit=msk.EncryptionInTransitConfig(\n client_broker=msk.ClientBrokerEncryption.TLS\n ),\n client_authentication=msk.ClientAuthentication.sasl_tls(\n iam=True,\n certificate_authorities=[\n acmpca.CertificateAuthority.from_certificate_authority_arn(self, \"CertificateAuthority\", \"arn:aws:acm-pca:us-west-2:1234567890:certificate-authority/11111111-1111-1111-1111-111111111111\")\n ]\n )\n)\n```\n\n## Logging\n\nYou can deliver Apache Kafka broker logs to one or more of the following destination types:\nAmazon CloudWatch Logs, Amazon S3, Amazon Kinesis Data Firehose.\n\nTo configure logs to be sent to an S3 bucket, provide a bucket in the `logging` config.\n\n```python\n# vpc: ec2.Vpc\n# bucket: s3.IBucket\n\ncluster = msk.Cluster(self, \"cluster\",\n cluster_name=\"myCluster\",\n kafka_version=msk.KafkaVersion.V2_8_1,\n vpc=vpc,\n logging=msk.BrokerLogging(\n s3=msk.S3LoggingConfiguration(\n bucket=bucket\n )\n )\n)\n```\n\nWhen the S3 destination is configured, AWS will automatically create an S3 bucket policy\nthat allows the service to write logs to the bucket. This makes it impossible to later update\nthat bucket policy. To have CDK create the bucket policy so that future updates can be made,\nthe `@aws-cdk/aws-s3:createDefaultLoggingPolicy` [feature flag](https://docs.aws.amazon.com/cdk/v2/guide/featureflags.html) can be used. This can be set\nin the `cdk.json` file.\n\n```json\n{\n \"context\": {\n \"@aws-cdk/aws-s3:createDefaultLoggingPolicy\": true\n }\n}\n```\n\n## Storage Mode\n\nYou can configure an MSK cluster storage mode using the `storageMode`\u00a0property.\n\nTiered storage is a low-cost storage tier for Amazon MSK that scales to virtually unlimited storage,\nmaking it cost-effective to build streaming data applications.\n\n> Visit [Tiered storage](https://docs.aws.amazon.com/msk/latest/developerguide/msk-tiered-storage.html)\n> to see the list of compatible Kafka versions and for more details.\n\n```python\n# vpc: ec2.Vpc\n# bucket: s3.IBucket\n\n\ncluster = msk.Cluster(self, \"cluster\",\n cluster_name=\"myCluster\",\n kafka_version=msk.KafkaVersion.V3_6_0,\n vpc=vpc,\n storage_mode=msk.StorageMode.TIERED\n)\n```\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "The CDK Construct Library for AWS::MSK",
"version": "2.170.0a0",
"project_urls": {
"Homepage": "https://github.com/aws/aws-cdk",
"Source": "https://github.com/aws/aws-cdk.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6d4bb5dfd834cf698bbebf716833dda4c7c8f60c813fa41ef53b746a9e7e76ab",
"md5": "bc7b2eea0c33504ff67f9108409923c2",
"sha256": "2c17b66138164b314d1299e5cdcaa6773602d41eac9c0e2076854dae717c5fe9"
},
"downloads": -1,
"filename": "aws_cdk.aws_msk_alpha-2.170.0a0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bc7b2eea0c33504ff67f9108409923c2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "~=3.8",
"size": 85741,
"upload_time": "2024-11-22T04:41:48",
"upload_time_iso_8601": "2024-11-22T04:41:48.916080Z",
"url": "https://files.pythonhosted.org/packages/6d/4b/b5dfd834cf698bbebf716833dda4c7c8f60c813fa41ef53b746a9e7e76ab/aws_cdk.aws_msk_alpha-2.170.0a0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d9071cf8b87b75ea86dbd2ac826c5659275a6fe174c8c64ae74fa1ab6937238a",
"md5": "af91e82c90c56001fdcd8095bde2c2d6",
"sha256": "3b676969e972a63ea967b949e2df61a45422c930bb98c9d408386f7b518f3c26"
},
"downloads": -1,
"filename": "aws_cdk_aws_msk_alpha-2.170.0a0.tar.gz",
"has_sig": false,
"md5_digest": "af91e82c90c56001fdcd8095bde2c2d6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "~=3.8",
"size": 87434,
"upload_time": "2024-11-22T04:42:33",
"upload_time_iso_8601": "2024-11-22T04:42:33.455191Z",
"url": "https://files.pythonhosted.org/packages/d9/07/1cf8b87b75ea86dbd2ac826c5659275a6fe174c8c64ae74fa1ab6937238a/aws_cdk_aws_msk_alpha-2.170.0a0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-22 04:42:33",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "aws",
"github_project": "aws-cdk",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "aws-cdk.aws-msk-alpha"
}