또는 와 CreateStreamAWS SDK 함께 사용 CLI - AWS SDK 코드 예제

AWS 문서 예제 리포지토리에서 더 많은 SDK GitHub AWS SDK 예제를 사용할 수 있습니다.

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

또는 와 CreateStreamAWS SDK 함께 사용 CLI

다음 코드 예제는 CreateStream의 사용 방법을 보여 줍니다.

작업 예제는 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 다음 코드 예제에서는 컨텍스트 내에서 이 작업을 확인할 수 있습니다.

.NET
AWS SDK for .NET
참고

에 대한 자세한 내용은 를 참조하세요 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.Threading.Tasks; using Amazon.Kinesis; using Amazon.Kinesis.Model; /// <summary> /// This example shows how to create a new Amazon Kinesis stream. /// </summary> public class CreateStream { public static async Task Main() { IAmazonKinesis client = new AmazonKinesisClient(); string streamName = "AmazonKinesisStream"; int shardCount = 1; var success = await CreateNewStreamAsync(client, streamName, shardCount); if (success) { Console.WriteLine($"The stream, {streamName} successfully created."); } } /// <summary> /// Creates a new Kinesis stream. /// </summary> /// <param name="client">An initialized Kinesis client.</param> /// <param name="streamName">The name for the new stream.</param> /// <param name="shardCount">The number of shards the new stream will /// use. The throughput of the stream is a function of the number of /// shards; more shards are required for greater provisioned /// throughput.</param> /// <returns>A Boolean value indicating whether the stream was created.</returns> public static async Task<bool> CreateNewStreamAsync(IAmazonKinesis client, string streamName, int shardCount) { var request = new CreateStreamRequest { StreamName = streamName, ShardCount = shardCount, }; var response = await client.CreateStreamAsync(request); return response.HttpStatusCode == System.Net.HttpStatusCode.OK; } }
  • 자세한 API 내용은 참조CreateStream의 섹션을 참조하세요. AWS SDK for .NET API

CLI
AWS CLI

데이터 스트림을 생성하는 방법

다음 create-stream 예시에서는 샤드 3개가 포함된 samplestream이라는 데이터 스트림을 생성합니다.

aws kinesis create-stream \ --stream-name samplestream \ --shard-count 3

이 명령은 출력을 생성하지 않습니다.

자세한 설명은 Amazon Kinesis Data Streams 개발자 안내서의 스트림 생성을 참조하세요.

  • 자세한 API 내용은 명령 참조CreateStream의 섹션을 참조하세요. AWS CLI

Java
SDK Java 2.x용
참고

에 대한 자세한 내용은 를 참조하세요 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.kinesis.KinesisClient; import software.amazon.awssdk.services.kinesis.model.CreateStreamRequest; import software.amazon.awssdk.services.kinesis.model.KinesisException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class CreateDataStream { public static void main(String[] args) { final String usage = """ Usage: <streamName> Where: streamName - The Amazon Kinesis data stream (for example, StockTradeStream). """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String streamName = args[0]; Region region = Region.US_EAST_1; KinesisClient kinesisClient = KinesisClient.builder() .region(region) .build(); createStream(kinesisClient, streamName); System.out.println("Done"); kinesisClient.close(); } public static void createStream(KinesisClient kinesisClient, String streamName) { try { CreateStreamRequest streamReq = CreateStreamRequest.builder() .streamName(streamName) .shardCount(1) .build(); kinesisClient.createStream(streamReq); } catch (KinesisException e) { System.err.println(e.getMessage()); System.exit(1); } } }
  • 자세한 API 내용은 참조CreateStream의 섹션을 참조하세요. AWS SDK for Java 2.x API

PowerShell
용 도구 PowerShell

예제 1: 새 스트림을 생성합니다. 기본적으로 이 cmdlet은 출력을 반환하지 않으므로 -PassThru 스위치가 추가되어 이후 사용을 위해 -StreamName 파라미터에 제공된 값을 반환합니다.

$streamName = New-KINStream -StreamName "mystream" -ShardCount 1 -PassThru
  • 자세한 API 내용은 Cmdlet 참조CreateStream의 섹션을 참조하세요. AWS Tools for PowerShell

Python
SDK Python용(Boto3)
참고

에 대한 자세한 내용은 를 참조하세요 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

class KinesisStream: """Encapsulates a Kinesis stream.""" def __init__(self, kinesis_client): """ :param kinesis_client: A Boto3 Kinesis client. """ self.kinesis_client = kinesis_client self.name = None self.details = None self.stream_exists_waiter = kinesis_client.get_waiter("stream_exists") def create(self, name, wait_until_exists=True): """ Creates a stream. :param name: The name of the stream. :param wait_until_exists: When True, waits until the service reports that the stream exists, then queries for its metadata. """ try: self.kinesis_client.create_stream(StreamName=name, ShardCount=1) self.name = name logger.info("Created stream %s.", name) if wait_until_exists: logger.info("Waiting until exists.") self.stream_exists_waiter.wait(StreamName=name) self.describe(name) except ClientError: logger.exception("Couldn't create stream %s.", name) raise
  • API 자세한 내용은 CreateStreamAWS SDK Python(Boto3) API 참조 섹션을 참조하세요.

Rust
SDK Rust용
참고

에 대한 자세한 내용은 를 참조하세요 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

async fn make_stream(client: &Client, stream: &str) -> Result<(), Error> { client .create_stream() .stream_name(stream) .shard_count(4) .send() .await?; println!("Created stream"); Ok(()) }
  • API 자세한 내용은 Rust 참조 CreateStream 의 섹션을 참조하세요. AWS SDK API

SAP ABAP
SDK 에 대한 SAP ABAP
참고

에 대한 자세한 내용은 를 참조하세요 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

TRY. lo_kns->createstream( iv_streamname = iv_stream_name iv_shardcount = iv_shard_count ). MESSAGE 'Stream created.' TYPE 'I'. CATCH /aws1/cx_knsinvalidargumentex. MESSAGE 'The specified argument was not valid.' TYPE 'E'. CATCH /aws1/cx_knslimitexceededex . MESSAGE 'The request processing has failed because of a limit exceed exception.' TYPE 'E'. CATCH /aws1/cx_knsresourceinuseex . MESSAGE 'The request processing has failed because the resource is in use.' TYPE 'E'. ENDTRY.
  • API 자세한 내용은 CreateStreamAWS SDK SAP ABAP API 섹션을 참조하세요.