AWS 문서 예제 리포지토리에서 더 많은 SDK
기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
KotlinSDK용 Amazon SQS 예제
다음 코드 예제에서는 Amazon 에서 Kotlin용 를 사용하여 작업을 수행하고 일반적인 시나리오를 AWS SDK 구현하는 방법을 보여줍니다SQS.
작업은 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 작업은 개별 서비스 함수를 직접적으로 호출하는 방법을 보여주며 관련 시나리오의 컨텍스트에 맞는 작업을 볼 수 있습니다.
시나리오는 동일한 서비스 내에서 또는 다른 AWS 서비스와 결합된 상태에서 여러 함수를 호출하여 특정 태스크를 수행하는 방법을 보여주는 코드 예제입니다.
각 예제에는 컨텍스트에서 코드를 설정하고 실행하는 방법에 대한 지침을 찾을 수 있는 전체 소스 코드에 대한 링크가 포함되어 있습니다.
시작하기
다음 코드 예제에서는 Amazon 를 시작하는 방법을 보여줍니다SQS.
- SDK Kotlin용
-
참고
에 대한 자세한 내용은 를 참조하세요 GitHub. AWS 코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. package com.kotlin.sqs import aws.sdk.kotlin.services.sqs.SqsClient import aws.sdk.kotlin.services.sqs.paginators.listQueuesPaginated import kotlinx.coroutines.flow.transform suspend fun main() { listTopicsPag() } suspend fun listTopicsPag() { SqsClient { region = "us-east-1" }.use { sqsClient -> sqsClient .listQueuesPaginated { } .transform { it.queueUrls?.forEach { queue -> emit(queue) } } .collect { queue -> println("The Queue URL is $queue") } } }
-
API 자세한 내용은 ListQueues
의 에서 AWS SDK Kotlin API 참조 를 참조하세요.
-
작업
다음 코드 예시에서는 CreateQueue
을 사용하는 방법을 보여 줍니다.
- SDK Kotlin용
-
참고
에 대한 자세한 내용은 를 참조하세요 GitHub. AWS 코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. suspend fun createQueue(queueNameVal: String): String { println("Create Queue") val createQueueRequest = CreateQueueRequest { queueName = queueNameVal } SqsClient { region = "us-east-1" }.use { sqsClient -> sqsClient.createQueue(createQueueRequest) println("Get queue url") val getQueueUrlRequest = GetQueueUrlRequest { queueName = queueNameVal } val getQueueUrlResponse = sqsClient.getQueueUrl(getQueueUrlRequest) return getQueueUrlResponse.queueUrl.toString() } }
-
API 자세한 내용은 CreateQueue
의 에서 AWS SDK Kotlin API 참조 를 참조하세요.
-
다음 코드 예시에서는 DeleteMessage
을 사용하는 방법을 보여 줍니다.
- SDK Kotlin용
-
참고
에 대한 자세한 내용은 를 참조하세요 GitHub. AWS 코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. suspend fun deleteMessages(queueUrlVal: String) { println("Delete Messages from $queueUrlVal") val purgeRequest = PurgeQueueRequest { queueUrl = queueUrlVal } SqsClient { region = "us-east-1" }.use { sqsClient -> sqsClient.purgeQueue(purgeRequest) println("Messages are successfully deleted from $queueUrlVal") } } suspend fun deleteQueue(queueUrlVal: String) { val request = DeleteQueueRequest { queueUrl = queueUrlVal } SqsClient { region = "us-east-1" }.use { sqsClient -> sqsClient.deleteQueue(request) println("$queueUrlVal was deleted!") } }
-
API 자세한 내용은 DeleteMessage
의 에서 AWS SDK Kotlin API 참조 를 참조하세요.
-
다음 코드 예시에서는 DeleteQueue
을 사용하는 방법을 보여 줍니다.
- SDK Kotlin용
-
참고
에 대한 자세한 내용은 를 참조하세요 GitHub. AWS 코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. suspend fun deleteMessages(queueUrlVal: String) { println("Delete Messages from $queueUrlVal") val purgeRequest = PurgeQueueRequest { queueUrl = queueUrlVal } SqsClient { region = "us-east-1" }.use { sqsClient -> sqsClient.purgeQueue(purgeRequest) println("Messages are successfully deleted from $queueUrlVal") } } suspend fun deleteQueue(queueUrlVal: String) { val request = DeleteQueueRequest { queueUrl = queueUrlVal } SqsClient { region = "us-east-1" }.use { sqsClient -> sqsClient.deleteQueue(request) println("$queueUrlVal was deleted!") } }
-
API 자세한 내용은 DeleteQueue
의 에서 AWS SDK Kotlin API 참조 를 참조하세요.
-
다음 코드 예시에서는 ListQueues
을 사용하는 방법을 보여 줍니다.
- SDK Kotlin용
-
참고
에 대한 자세한 내용은 를 참조하세요 GitHub. AWS 코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. suspend fun listQueues() { println("\nList Queues") val prefix = "que" val listQueuesRequest = ListQueuesRequest { queueNamePrefix = prefix } SqsClient { region = "us-east-1" }.use { sqsClient -> val response = sqsClient.listQueues(listQueuesRequest) response.queueUrls?.forEach { url -> println(url) } } }
-
API 자세한 내용은 ListQueues
의 에서 AWS SDK Kotlin API 참조 를 참조하세요.
-
다음 코드 예시에서는 ReceiveMessage
을 사용하는 방법을 보여 줍니다.
- SDK Kotlin용
-
참고
에 대한 자세한 내용은 를 참조하세요 GitHub. AWS 코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. suspend fun receiveMessages(queueUrlVal: String?) { println("Retrieving messages from $queueUrlVal") val receiveMessageRequest = ReceiveMessageRequest { queueUrl = queueUrlVal maxNumberOfMessages = 5 } SqsClient { region = "us-east-1" }.use { sqsClient -> val response = sqsClient.receiveMessage(receiveMessageRequest) response.messages?.forEach { message -> println(message.body) } } }
-
API 자세한 내용은 ReceiveMessage
의 에서 AWS SDK Kotlin API 참조 를 참조하세요.
-
다음 코드 예시에서는 SendMessage
을 사용하는 방법을 보여 줍니다.
- SDK Kotlin용
-
참고
에 대한 자세한 내용은 를 참조하세요 GitHub. AWS 코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. suspend fun sendMessages( queueUrlVal: String, message: String, ) { println("Sending multiple messages") println("\nSend message") val sendRequest = SendMessageRequest { queueUrl = queueUrlVal messageBody = message delaySeconds = 10 } SqsClient { region = "us-east-1" }.use { sqsClient -> sqsClient.sendMessage(sendRequest) println("A single message was successfully sent.") } } suspend fun sendBatchMessages(queueUrlVal: String?) { println("Sending multiple messages") val msg1 = SendMessageBatchRequestEntry { id = "id1" messageBody = "Hello from msg 1" } val msg2 = SendMessageBatchRequestEntry { id = "id2" messageBody = "Hello from msg 2" } val sendMessageBatchRequest = SendMessageBatchRequest { queueUrl = queueUrlVal entries = listOf(msg1, msg2) } SqsClient { region = "us-east-1" }.use { sqsClient -> sqsClient.sendMessageBatch(sendMessageBatchRequest) println("Batch message were successfully sent.") } }
-
API 자세한 내용은 SendMessage
의 에서 AWS SDK Kotlin API 참조 를 참조하세요.
-
시나리오
다음 코드 예제에서는 Amazon 를 사용하여 메시징 애플리케이션을 생성하는 방법을 보여줍니다SQS.
- SDK Kotlin용
-
Amazon을 사용하여 메시지를 보내고 검색RESTAPI하는 스프링을 SQS API 개발하는 방법을 보여줍니다.
전체 소스 코드와 설정 및 실행 방법에 대한 지침은 의 전체 예제를 참조하세요GitHub
. 이 예시에서 사용되는 서비스
Amazon Comprehend
Amazon SQS
다음 코드 예시는 다음과 같은 작업을 수행하는 방법을 보여줍니다.
주제(FIFO 또는 비)를 생성합니다FIFO.
필터 적용 옵션을 사용하여 여러 개의 대기열로 주제를 구독합니다.
주제에 메시지를 게시합니다.
대기열에서 받은 메시지를 폴링합니다.
- SDK Kotlin용
-
참고
에 대한 자세한 내용은 를 참조하세요 GitHub. AWS 코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. package com.example.sns import aws.sdk.kotlin.services.sns.SnsClient import aws.sdk.kotlin.services.sns.model.CreateTopicRequest import aws.sdk.kotlin.services.sns.model.DeleteTopicRequest import aws.sdk.kotlin.services.sns.model.PublishRequest import aws.sdk.kotlin.services.sns.model.SetSubscriptionAttributesRequest import aws.sdk.kotlin.services.sns.model.SubscribeRequest import aws.sdk.kotlin.services.sns.model.UnsubscribeRequest import aws.sdk.kotlin.services.sqs.SqsClient import aws.sdk.kotlin.services.sqs.model.CreateQueueRequest import aws.sdk.kotlin.services.sqs.model.DeleteMessageBatchRequest import aws.sdk.kotlin.services.sqs.model.DeleteMessageBatchRequestEntry import aws.sdk.kotlin.services.sqs.model.DeleteQueueRequest import aws.sdk.kotlin.services.sqs.model.GetQueueAttributesRequest import aws.sdk.kotlin.services.sqs.model.GetQueueUrlRequest import aws.sdk.kotlin.services.sqs.model.Message import aws.sdk.kotlin.services.sqs.model.QueueAttributeName import aws.sdk.kotlin.services.sqs.model.ReceiveMessageRequest import aws.sdk.kotlin.services.sqs.model.SetQueueAttributesRequest import com.google.gson.Gson import com.google.gson.JsonObject import com.google.gson.JsonPrimitive import java.util.Scanner /** Before running this Kotlin code example, set up your development environment, including your AWS credentials. For more information, see the following documentation topic: https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html This Kotlin example performs the following tasks: 1. Gives the user three options to choose from. 2. Creates an Amazon Simple Notification Service (Amazon SNS) topic. 3. Creates an Amazon Simple Queue Service (Amazon SQS) queue. 4. Gets the SQS queue Amazon Resource Name (ARN) attribute. 5. Attaches an AWS Identity and Access Management (IAM) policy to the queue. 6. Subscribes to the SQS queue. 7. Publishes a message to the topic. 8. Displays the messages. 9. Deletes the received message. 10. Unsubscribes from the topic. 11. Deletes the SNS topic. */ val DASHES: String = String(CharArray(80)).replace("\u0000", "-") suspend fun main() { val input = Scanner(System.`in`) val useFIFO: String var duplication = "n" var topicName: String var deduplicationID: String? = null var groupId: String? = null val topicArn: String? var sqsQueueName: String val sqsQueueUrl: String? val sqsQueueArn: String val subscriptionArn: String? var selectFIFO = false val message: String val messageList: List<Message?>? val filterList = ArrayList<String>() var msgAttValue = "" println(DASHES) println("Welcome to the AWS SDK for Kotlin messaging with topics and queues.") println( """ In this workflow, you will create an SNS topic and subscribe an SQS queue to the topic. You can select from several options for configuring the topic and the subscriptions for the queue. You can then post to the topic and see the results in the queue. """.trimIndent(), ) println(DASHES) println(DASHES) println( """ SNS topics can be configured as FIFO (First-In-First-Out). FIFO topics deliver messages in order and support deduplication and message filtering. Would you like to work with FIFO topics? (y/n) """.trimIndent(), ) useFIFO = input.nextLine() if (useFIFO.compareTo("y") == 0) { selectFIFO = true println("You have selected FIFO") println( """ Because you have chosen a FIFO topic, deduplication is supported. Deduplication IDs are either set in the message or automatically generated from content using a hash function. If a message is successfully published to an SNS FIFO topic, any message published and determined to have the same deduplication ID, within the five-minute deduplication interval, is accepted but not delivered. For more information about deduplication, see https://docs.aws.amazon.com/sns/latest/dg/fifo-message-dedup.html.""", ) println("Would you like to use content-based deduplication instead of entering a deduplication ID? (y/n)") duplication = input.nextLine() if (duplication.compareTo("y") == 0) { println("Enter a group id value") groupId = input.nextLine() } else { println("Enter deduplication Id value") deduplicationID = input.nextLine() println("Enter a group id value") groupId = input.nextLine() } } println(DASHES) println(DASHES) println("2. Create a topic.") println("Enter a name for your SNS topic.") topicName = input.nextLine() if (selectFIFO) { println("Because you have selected a FIFO topic, '.fifo' must be appended to the topic name.") topicName = "$topicName.fifo" println("The name of the topic is $topicName") topicArn = createFIFO(topicName, duplication) println("The ARN of the FIFO topic is $topicArn") } else { println("The name of the topic is $topicName") topicArn = createSNSTopic(topicName) println("The ARN of the non-FIFO topic is $topicArn") } println(DASHES) println(DASHES) println("3. Create an SQS queue.") println("Enter a name for your SQS queue.") sqsQueueName = input.nextLine() if (selectFIFO) { sqsQueueName = "$sqsQueueName.fifo" } sqsQueueUrl = createQueue(sqsQueueName, selectFIFO) println("The queue URL is $sqsQueueUrl") println(DASHES) println(DASHES) println("4. Get the SQS queue ARN attribute.") sqsQueueArn = getSQSQueueAttrs(sqsQueueUrl) println("The ARN of the new queue is $sqsQueueArn") println(DASHES) println(DASHES) println("5. Attach an IAM policy to the queue.") // Define the policy to use. val policy = """{ "Statement": [ { "Effect": "Allow", "Principal": { "Service": "sns.amazonaws.com" }, "Action": "sqs:SendMessage", "Resource": "$sqsQueueArn", "Condition": { "ArnEquals": { "aws:SourceArn": "$topicArn" } } } ] }""" setQueueAttr(sqsQueueUrl, policy) println(DASHES) println(DASHES) println("6. Subscribe to the SQS queue.") if (selectFIFO) { println( """If you add a filter to this subscription, then only the filtered messages will be received in the queue. For information about message filtering, see https://docs.aws.amazon.com/sns/latest/dg/sns-message-filtering.html For this example, you can filter messages by a "tone" attribute.""", ) println("Would you like to filter messages for $sqsQueueName's subscription to the topic $topicName? (y/n)") val filterAns: String = input.nextLine() if (filterAns.compareTo("y") == 0) { var moreAns = false println("You can filter messages by using one or more of the following \"tone\" attributes.") println("1. cheerful") println("2. funny") println("3. serious") println("4. sincere") while (!moreAns) { println("Select a number or choose 0 to end.") val ans: String = input.nextLine() when (ans) { "1" -> filterList.add("cheerful") "2" -> filterList.add("funny") "3" -> filterList.add("serious") "4" -> filterList.add("sincere") else -> moreAns = true } } } } subscriptionArn = subQueue(topicArn, sqsQueueArn, filterList) println(DASHES) println(DASHES) println("7. Publish a message to the topic.") if (selectFIFO) { println("Would you like to add an attribute to this message? (y/n)") val msgAns: String = input.nextLine() if (msgAns.compareTo("y") == 0) { println("You can filter messages by one or more of the following \"tone\" attributes.") println("1. cheerful") println("2. funny") println("3. serious") println("4. sincere") println("Select a number or choose 0 to end.") val ans: String = input.nextLine() msgAttValue = when (ans) { "1" -> "cheerful" "2" -> "funny" "3" -> "serious" else -> "sincere" } println("Selected value is $msgAttValue") } println("Enter a message.") message = input.nextLine() pubMessageFIFO(message, topicArn, msgAttValue, duplication, groupId, deduplicationID) } else { println("Enter a message.") message = input.nextLine() pubMessage(message, topicArn) } println(DASHES) println(DASHES) println("8. Display the message. Press any key to continue.") input.nextLine() messageList = receiveMessages(sqsQueueUrl, msgAttValue) if (messageList != null) { for (mes in messageList) { println("Message Id: ${mes.messageId}") println("Full Message: ${mes.body}") } } println(DASHES) println(DASHES) println("9. Delete the received message. Press any key to continue.") input.nextLine() if (messageList != null) { deleteMessages(sqsQueueUrl, messageList) } println(DASHES) println(DASHES) println("10. Unsubscribe from the topic and delete the queue. Press any key to continue.") input.nextLine() unSub(subscriptionArn) deleteSQSQueue(sqsQueueName) println(DASHES) println(DASHES) println("11. Delete the topic. Press any key to continue.") input.nextLine() deleteSNSTopic(topicArn) println(DASHES) println(DASHES) println("The SNS/SQS workflow has completed successfully.") println(DASHES) } suspend fun deleteSNSTopic(topicArnVal: String?) { val request = DeleteTopicRequest { topicArn = topicArnVal } SnsClient { region = "us-east-1" }.use { snsClient -> snsClient.deleteTopic(request) println("$topicArnVal was deleted") } } suspend fun deleteSQSQueue(queueNameVal: String) { val getQueueRequest = GetQueueUrlRequest { queueName = queueNameVal } SqsClient { region = "us-east-1" }.use { sqsClient -> val queueUrlVal = sqsClient.getQueueUrl(getQueueRequest).queueUrl val deleteQueueRequest = DeleteQueueRequest { queueUrl = queueUrlVal } sqsClient.deleteQueue(deleteQueueRequest) println("$queueNameVal was successfully deleted.") } } suspend fun unSub(subscripArn: String?) { val request = UnsubscribeRequest { subscriptionArn = subscripArn } SnsClient { region = "us-east-1" }.use { snsClient -> snsClient.unsubscribe(request) println("Subscription was removed for $subscripArn") } } suspend fun deleteMessages(queueUrlVal: String?, messages: List<Message>) { val entriesVal: MutableList<DeleteMessageBatchRequestEntry> = mutableListOf() for (msg in messages) { val entry = DeleteMessageBatchRequestEntry { id = msg.messageId } entriesVal.add(entry) } val deleteMessageBatchRequest = DeleteMessageBatchRequest { queueUrl = queueUrlVal entries = entriesVal } SqsClient { region = "us-east-1" }.use { sqsClient -> sqsClient.deleteMessageBatch(deleteMessageBatchRequest) println("The batch delete of messages was successful") } } suspend fun receiveMessages(queueUrlVal: String?, msgAttValue: String): List<Message>? { if (msgAttValue.isEmpty()) { val request = ReceiveMessageRequest { queueUrl = queueUrlVal maxNumberOfMessages = 5 } SqsClient { region = "us-east-1" }.use { sqsClient -> return sqsClient.receiveMessage(request).messages } } else { val receiveRequest = ReceiveMessageRequest { queueUrl = queueUrlVal waitTimeSeconds = 1 maxNumberOfMessages = 5 } SqsClient { region = "us-east-1" }.use { sqsClient -> return sqsClient.receiveMessage(receiveRequest).messages } } } suspend fun pubMessage(messageVal: String?, topicArnVal: String?) { val request = PublishRequest { message = messageVal topicArn = topicArnVal } SnsClient { region = "us-east-1" }.use { snsClient -> val result = snsClient.publish(request) println("${result.messageId} message sent.") } } suspend fun pubMessageFIFO( messageVal: String?, topicArnVal: String?, msgAttValue: String, duplication: String, groupIdVal: String?, deduplicationID: String?, ) { // Means the user did not choose to use a message attribute. if (msgAttValue.isEmpty()) { if (duplication.compareTo("y") == 0) { val request = PublishRequest { message = messageVal messageGroupId = groupIdVal topicArn = topicArnVal } SnsClient { region = "us-east-1" }.use { snsClient -> val result = snsClient.publish(request) println(result.messageId.toString() + " Message sent.") } } else { val request = PublishRequest { message = messageVal messageDeduplicationId = deduplicationID messageGroupId = groupIdVal topicArn = topicArnVal } SnsClient { region = "us-east-1" }.use { snsClient -> val result = snsClient.publish(request) println(result.messageId.toString() + " Message sent.") } } } else { val messAttr = aws.sdk.kotlin.services.sns.model.MessageAttributeValue { dataType = "String" stringValue = "true" } val mapAtt: Map<String, aws.sdk.kotlin.services.sns.model.MessageAttributeValue> = mapOf(msgAttValue to messAttr) if (duplication.compareTo("y") == 0) { val request = PublishRequest { message = messageVal messageGroupId = groupIdVal topicArn = topicArnVal } SnsClient { region = "us-east-1" }.use { snsClient -> val result = snsClient.publish(request) println(result.messageId.toString() + " Message sent.") } } else { // Create a publish request with the message and attributes. val request = PublishRequest { topicArn = topicArnVal message = messageVal messageDeduplicationId = deduplicationID messageGroupId = groupIdVal messageAttributes = mapAtt } SnsClient { region = "us-east-1" }.use { snsClient -> val result = snsClient.publish(request) println(result.messageId.toString() + " Message sent.") } } } } // Subscribe to the SQS queue. suspend fun subQueue(topicArnVal: String?, queueArnVal: String, filterList: List<String?>): String? { val request: SubscribeRequest if (filterList.isEmpty()) { // No filter subscription is added. request = SubscribeRequest { protocol = "sqs" endpoint = queueArnVal returnSubscriptionArn = true topicArn = topicArnVal } SnsClient { region = "us-east-1" }.use { snsClient -> val result = snsClient.subscribe(request) println( "The queue " + queueArnVal + " has been subscribed to the topic " + topicArnVal + "\n" + "with the subscription ARN " + result.subscriptionArn, ) return result.subscriptionArn } } else { request = SubscribeRequest { protocol = "sqs" endpoint = queueArnVal returnSubscriptionArn = true topicArn = topicArnVal } SnsClient { region = "us-east-1" }.use { snsClient -> val result = snsClient.subscribe(request) println("The queue $queueArnVal has been subscribed to the topic $topicArnVal with the subscription ARN ${result.subscriptionArn}") val attributeNameVal = "FilterPolicy" val gson = Gson() val jsonString = "{\"tone\": []}" val jsonObject = gson.fromJson(jsonString, JsonObject::class.java) val toneArray = jsonObject.getAsJsonArray("tone") for (value: String? in filterList) { toneArray.add(JsonPrimitive(value)) } val updatedJsonString: String = gson.toJson(jsonObject) println(updatedJsonString) val attRequest = SetSubscriptionAttributesRequest { subscriptionArn = result.subscriptionArn attributeName = attributeNameVal attributeValue = updatedJsonString } snsClient.setSubscriptionAttributes(attRequest) return result.subscriptionArn } } } suspend fun setQueueAttr(queueUrlVal: String?, policy: String) { val attrMap: MutableMap<String, String> = HashMap() attrMap[QueueAttributeName.Policy.toString()] = policy val attributesRequest = SetQueueAttributesRequest { queueUrl = queueUrlVal attributes = attrMap } SqsClient { region = "us-east-1" }.use { sqsClient -> sqsClient.setQueueAttributes(attributesRequest) println("The policy has been successfully attached.") } } suspend fun getSQSQueueAttrs(queueUrlVal: String?): String { val atts: MutableList<QueueAttributeName> = ArrayList() atts.add(QueueAttributeName.QueueArn) val attributesRequest = GetQueueAttributesRequest { queueUrl = queueUrlVal attributeNames = atts } SqsClient { region = "us-east-1" }.use { sqsClient -> val response = sqsClient.getQueueAttributes(attributesRequest) val mapAtts = response.attributes if (mapAtts != null) { mapAtts.forEach { entry -> println("${entry.key} : ${entry.value}") return entry.value } } } return "" } suspend fun createQueue(queueNameVal: String?, selectFIFO: Boolean): String? { println("\nCreate Queue") if (selectFIFO) { val attrs = mutableMapOf<String, String>() attrs[QueueAttributeName.FifoQueue.toString()] = "true" val createQueueRequest = CreateQueueRequest { queueName = queueNameVal attributes = attrs } SqsClient { region = "us-east-1" }.use { sqsClient -> sqsClient.createQueue(createQueueRequest) println("\nGet queue url") val urlRequest = GetQueueUrlRequest { queueName = queueNameVal } val getQueueUrlResponse = sqsClient.getQueueUrl(urlRequest) return getQueueUrlResponse.queueUrl } } else { val createQueueRequest = CreateQueueRequest { queueName = queueNameVal } SqsClient { region = "us-east-1" }.use { sqsClient -> sqsClient.createQueue(createQueueRequest) println("Get queue url") val urlRequest = GetQueueUrlRequest { queueName = queueNameVal } val getQueueUrlResponse = sqsClient.getQueueUrl(urlRequest) return getQueueUrlResponse.queueUrl } } } suspend fun createSNSTopic(topicName: String?): String? { val request = CreateTopicRequest { name = topicName } SnsClient { region = "us-east-1" }.use { snsClient -> val result = snsClient.createTopic(request) return result.topicArn } } suspend fun createFIFO(topicName: String?, duplication: String): String? { val topicAttributes: MutableMap<String, String> = HashMap() if (duplication.compareTo("n") == 0) { topicAttributes["FifoTopic"] = "true" topicAttributes["ContentBasedDeduplication"] = "false" } else { topicAttributes["FifoTopic"] = "true" topicAttributes["ContentBasedDeduplication"] = "true" } val topicRequest = CreateTopicRequest { name = topicName attributes = topicAttributes } SnsClient { region = "us-east-1" }.use { snsClient -> val response = snsClient.createTopic(topicRequest) return response.topicArn } }
-
API 자세한 내용은 의 다음 주제에서 AWS SDK Kotlin API 참조 를 참조하세요.
-