Use CreateMultiRegionAccessPoint with an Amazon SDK or CLI - Amazon Simple Storage Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Use CreateMultiRegionAccessPoint with an Amazon SDK or CLI

The following code example shows how to use CreateMultiRegionAccessPoint.

Kotlin
SDK for Kotlin
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

Configure the S3 control client to send request to the us-west-2 Region.

suspend fun createS3ControlClient(): S3ControlClient { // Configure your S3ControlClient to send requests to US West (Oregon). val s3Control = S3ControlClient.fromEnvironment { region = "us-west-2" } return s3Control }

Create the Multi-Region Access Point.

suspend fun createMrap(s3Control: S3ControlClient, accountIdParam: String, bucketName1: String, bucketName2: String, mrapName: String): String { println("Creating MRAP ...") val createMrapResponse: CreateMultiRegionAccessPointResponse = s3Control.createMultiRegionAccessPoint { accountId = accountIdParam clientToken = UUID.randomUUID().toString() details { name = mrapName regions = listOf( Region { bucket = bucketName1 }, Region { bucket = bucketName2 } ) } } val requestToken: String? = createMrapResponse.requestTokenArn // Use the request token to check for the status of the CreateMultiRegionAccessPoint operation. if (requestToken != null) { waitForSucceededStatus(s3Control, requestToken, accountIdParam) println("MRAP created") } val getMrapResponse = s3Control.getMultiRegionAccessPoint( input = GetMultiRegionAccessPointRequest { accountId = accountIdParam name = mrapName } ) val mrapAlias = getMrapResponse.accessPoint?.alias return "arn:aws:s3::$accountIdParam:accesspoint/$mrapAlias" }

Wait for the Multi-Region Access Point to become available.

suspend fun waitForSucceededStatus(s3Control: S3ControlClient, requestToken: String, accountIdParam: String, timeBetweenChecks: Duration = 1.minutes) { var describeResponse: DescribeMultiRegionAccessPointOperationResponse describeResponse = s3Control.describeMultiRegionAccessPointOperation( input = DescribeMultiRegionAccessPointOperationRequest { accountId = accountIdParam requestTokenArn = requestToken } ) var status: String? = describeResponse.asyncOperation?.requestStatus while (status != "SUCCEEDED") { delay(timeBetweenChecks) describeResponse = s3Control.describeMultiRegionAccessPointOperation( input = DescribeMultiRegionAccessPointOperationRequest { accountId = accountIdParam requestTokenArn = requestToken } ) status = describeResponse.asyncOperation?.requestStatus println(status) } }

For a complete list of Amazon SDK developer guides and code examples, see Using this service with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.