diff --git a/docs/src/main/asciidoc/cloud-map.adoc b/docs/src/main/asciidoc/cloud-map.adoc new file mode 100644 index 000000000..2bb8b2496 --- /dev/null +++ b/docs/src/main/asciidoc/cloud-map.adoc @@ -0,0 +1,266 @@ +[#spring-cloud-aws-cloudmap] +== Spring Cloud AWS CloudMap +This article talks about the new Spring Cloud AWS CloudMap module. + +=== What is service discovery? + +Service discovery is the mechanism through which a microservices can locate other microservices in the network. Service discovery is a critical part of microservices architecture as it enables the microservices to identify and communicate with each other. + +There are two types of service discovery: Server-side and Client-side. + + 1. Server-side service discovery allows clients applications to find other services through a router (like API gateway or a load balancer). + 2. Client-side service discovery allows clients applications to find services by looking through or querying a service registry, in which service instances and endpoints are all within the service registry. + +=== What is AWS Cloud Map? +https://aws.amazon.com/cloud-map/[AWS Cloud Map] is a client-side service registry and service discovery solution provided as a ready-to-use, highly available service. Rather than build your own client service registry, you can leverage AWS Cloud Map to register your application and its running instances, and then use either the AWS Cloud Map API or DNS lookup to resolve a service's name to a current active endpoint. + +With Cloud Map, you can define custom names for your application resources, and it maintains the updated location of these dynamically changing resources. This increases your application availability because your web service always discovers the most up-to-date locations of its resources. + +=== Spring Cloud integration with AWS Cloud Map + +Spring Cloud AWS adds support for registering and discovering service using AWS Cloud Map through Spring Boot https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-files-importing[config import feature]. + +Maven coordinates, using <>: + +[source,xml] +---- + + io.awspring.cloud + spring-cloud-aws-starter-aws-cloudmap + +---- + + +=== Service registration +To register a microservice to Cloud Map we need to specify the following: + + 1. Namespace - A namespace is a way to group services for an application. When you create a namespace, you specify how you want to discover service instances that you register with AWS Cloud Map + 2. Service name - A service is a template for registering service instances, which allow you to locate the resources for an application using AWS Cloud Map `DiscoverInstances` API action + 3. Service Instance - A service instance contains information about how to locate a resource, such as a web server, for an application. After you register instances, you locate them by using AWS Cloud Map `DiscoverInstances` API action. + +Spring Cloud integration with AWS Cloud Map allows you to register a microservice to Cloud Map using the following configuration: + + 1. Automatic registration - Spring Cloud AWS Cloud Map module automatically registers the microservice to Cloud Map when the application starts. In order to do this, just include `spring-cloud-aws-starter-aws-cloudmap` dependency in your application, and Cloud Map integration module will register your microservice under `default-namespace` namespace and `spring.application.name or default-service` service name. + 2. Manual registration - Cloud Map properties can be provided part of the application configuration, here is a sample: + +```properties +spring.cloud.aws.cloudmap.registry.description=Namespace for sample cloudmap registry service +spring.cloud.aws.cloudmap.registry.port=80 +spring.cloud.aws.cloudmap.registry.service=a-service +spring.cloud.aws.cloudmap.registry.nameSpace=a-namespace +``` + +=== Service discovery +To discover a microservice using Cloud Map we need to specify the following: + +Enable `DiscoveryClient` - You can use `@EnableDiscoveryClient` annotation to integrate with Spring Cloud `DiscoveryClient`, here is a sample: + +```java +@SpringBootApplication +@EnableDiscoveryClient +public class SpringCloudAwsCloudMapSample { + @Autowired + private DiscoveryClient discoveryClient; + + @Bean + ApplicationRunner applicationRunner() { + return args -> LOGGER.info("Total instances: {}", discoveryClient.getServices().size()); + } +} +``` +* Using application configuration to specify the services - You can specify the services that can be discovered using `spring.cloud.aws.cloudmap.discovery.*` property, here is a sample: + +```properties +spring.cloud.aws.cloudmap.discovery.discoveryList[0].service=a-service #array of services +spring.cloud.aws.cloudmap.discovery.discoveryList[0].nameSpace=a-namespace +``` + +=== Using ServiceDiscoveryClient + +The starter automatically configures and registers a `ServiceDiscoveryClient` bean in the Spring application context. The `ServiceDiscoveryClient` bean can be used to register or discovery service instances from AWS Cloud Map. + +[source,java] +---- +import org.springframework.stereotype.Component; +import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryClient; +... +@Autowired +private ServiceDiscoveryClient serviceDiscoveryClient; +... +Map attributes = new HashMap<>(); +attributes.put(AWS_INSTANCE_IPV_4, registrationDetails.get(IPV_4_ADDRESS)); +attributes.put(REGION, System.getenv("AWS_REGION")); +attributes.put(NAMESPACE_ID, nameSpaceId); +attributes.put(SERVICE_ID, serviceId); +attributes.put(SERVICE_INSTANCE_ID, serviceInstanceId); + +// Register instance +final String operationId = serviceDiscovery.registerInstance(RegisterInstanceRequest.builder() + .instanceId(serviceInstanceId).serviceId(serviceId).attributes(attributes).build()) + .operationId(); +---- + +=== Customizing ServiceDiscoveryClient + +To use custom `ServiceDiscoveryClient` in `spring.config.import`, provide an implementation of `BootstrapRegistryInitializer`. For example: + +[source,java] +---- +package com.app; + +import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; +import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryClient; + +import org.springframework.boot.BootstrapRegistry; +import org.springframework.boot.BootstrapRegistryInitializer; + +class AWSCloudMapBootstrapConfiguration implements BootstrapRegistryInitializer { + + @Override + public void initialize(BootstrapRegistry registry) { + registry.register(ServiceDiscoveryClient.class, context -> { + AwsCredentialsProvider awsCredentialsProvider = StaticCredentialsProvider.create(AwsBasicCredentials.create("yourAccessKey", "yourSecretKey")); + return ServiceDiscoveryClient.builder().credentialsProvider(awsCredentialsProvider).region(Region.EU_WEST_2).build(); + }); + } +} +---- + +--- + +Note that this class must be listed under `org.springframework.boot.BootstrapRegistryInitializer` key in `META-INF/spring.factories`: + +[source, properties] +---- +org.springframework.boot.BootstrapRegistryInitializer=com.app.AWSCloudMapBootstrapConfiguration +---- + +Note that this class must be listed under `org.springframework.boot.BootstrapRegistryInitializer` key in `META-INF/spring.factories`: + +[source, properties] +---- +org.springframework.boot.BootstrapRegistryInitializer=com.app.AWSCloudMapBootstrapConfiguration +---- + +If you want to use autoconfigured `ServiceDiscoveryClient` but change underlying SDKClient or ClientOverrideConfiguration you will need to register bean of type `AwsClientConfigurerCloudMap`: +Autoconfiguration will configure `ServiceDiscoveryClient` Bean with provided values after that, for example: + +If you want to use autoconfigured `ServiceDiscoveryClient` but change underlying SDKClient or ClientOverrideConfiguration you will need to register bean of type `AwsClientConfigurerCloudMap`: +Autoconfiguration will configure `ServiceDiscoveryClient` Bean with provided values after that, for example: + +[source,java] +---- +package com.app; + +import io.awspring.cloud.autoconfigure.cloudmap.AwsCloudMapStoreClientCustomizer; +import java.time.Duration; +import org.springframework.boot.BootstrapRegistry; +import org.springframework.boot.BootstrapRegistryInitializer; +import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; +import software.amazon.awssdk.http.SdkHttpClient; +import software.amazon.awssdk.http.apache.ApacheHttpClient; +import software.amazon.awssdk.services.ssm.SsmClientBuilder; + +class AWSCloudMapBootstrapConfiguration implements BootstrapRegistryInitializer { + + @Override + public void initialize(BootstrapRegistry registry) { + registry.register(AwsCloudMapStoreClientCustomizer.class, + context -> new AwsCloudMapStoreClientCustomizer() { + + @Override + public ClientOverrideConfiguration overrideConfiguration() { + return ClientOverrideConfiguration.builder().apiCallTimeout(Duration.ofMillis(500)) + .build(); + } + + @Override + public SdkHttpClient httpClient() { + return ApacheHttpClient.builder().connectionTimeout(Duration.ofMillis(1000)).build(); + } + }); + } +} +---- + +=== Configuration + +The Spring Boot Starter for Cloud Map integration provides the following configuration options for service registration: + +[cols="4,3,1,1"] +|=== +| Name | Description | Required | Default value + +| `spring.cloud.aws.cloudmap.registry.description` | Namespace for sample cloudmap registry service. | No | `default-namespace` +| `spring.cloud.aws.cloudmap.registry.port` | Port in which the microservice is exposed. | No | `null` +| `spring.cloud.aws.cloudmap.registry.service` | Service name for registering the cloudmap service. | No | `default-service or spring.application.name` +| `spring.cloud.aws.cloudmap.region` | Configures region used by `ServiceDiscoveryClient`. | No | `null` +|=== + + +The Spring Boot Starter for Cloud Map integration provides the following configuration options for discovering services: + +[cols="4,3,1,1"] +|=== +| Name | Description | Required | Default value + +| `spring.cloud.aws.cloudmap.discovery.discoveryList[*].service` | Array of Cloudmap services the module will discover part of the startup. | No | `null` +| `spring.cloud.aws.cloudmap.discovery.discoveryList[*].nameSpace` | Array of Cloudmap namespaces the module will discover part of the startup. | No | `null` +| `spring.cloud.aws.cloudmap.region` | Configures region used by `ServiceDiscoveryClient`. | No | `null` +|=== + +=== IAM Permissions +Following IAM permissions are required by Spring Cloud AWS to register and discover services in AWS Cloud Map: + +[cols="1"] +|=== +| **Policies** +| `servicediscovery:ListServices` +| `servicediscovery:GetOperation` +| `servicediscovery:DiscoverInstances` +| `servicediscovery:DeleteNamespace` +| `servicediscovery:ListNamespaces` +| `servicediscovery:RegisterInstance` +| `servicediscovery:CreateService` +| `servicediscovery:DeregisterInstance` +| `servicediscovery:DeleteService` +| `servicediscovery:GetNamespace` +| `servicediscovery:GetInstance` +| `servicediscovery:GetService` +| `servicediscovery:ListInstances` +|=== + +Sample IAM policy: + +[source,json,indent=0] +---- +{ + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "Sid1", + "Effect": "Allow", + "Action": [ + "servicediscovery:ListServices", + "servicediscovery:GetOperation", + "servicediscovery:DiscoverInstances", + "servicediscovery:DeleteNamespace", + "servicediscovery:ListNamespaces", + "servicediscovery:RegisterInstance", + "servicediscovery:CreateService", + "servicediscovery:DeregisterInstance", + "servicediscovery:DeleteService", + "servicediscovery:GetNamespace", + "servicediscovery:GetInstance", + "servicediscovery:GetService", + "servicediscovery:ListInstances" + ], + "Resource": "*" + } + ] +} +---- + diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/AwsCloudMapStoreClientCustomizer.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/AwsCloudMapStoreClientCustomizer.java new file mode 100644 index 000000000..eeffa310b --- /dev/null +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/AwsCloudMapStoreClientCustomizer.java @@ -0,0 +1,26 @@ +/* + * Copyright 2013-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.awspring.cloud.autoconfigure.cloudmap; + +import io.awspring.cloud.autoconfigure.core.AwsClientCustomizer; +import software.amazon.awssdk.services.ssm.SsmClientBuilder; + +/** + * @author Hari Ohm Prasath + * @since 3.0.0 + */ +public interface AwsCloudMapStoreClientCustomizer extends AwsClientCustomizer { +} diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapBootstrapConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapAutoConfiguration.java similarity index 90% rename from spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapBootstrapConfiguration.java rename to spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapAutoConfiguration.java index bb37b6084..9aac8e2bd 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapBootstrapConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapAutoConfiguration.java @@ -22,7 +22,6 @@ import io.awspring.cloud.autoconfigure.core.AwsClientBuilderConfigurer; import io.awspring.cloud.autoconfigure.core.AwsClientCustomizer; import org.springframework.beans.factory.ObjectProvider; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -40,14 +39,13 @@ */ @Configuration(proxyBeanMethods = false) @EnableConfigurationProperties(CloudMapProperties.class) -@ConditionalOnClass({ ServiceDiscoveryClient.class, ServiceRegistration.class, CloudMapAutoRegistration.class }) @ConditionalOnProperty(prefix = CloudMapProperties.CONFIG_PREFIX, name = "enabled", matchIfMissing = true) -public class CloudMapBootstrapConfiguration { +public class CloudMapAutoConfiguration { private final ApplicationContext context; private final CloudMapProperties properties; - public CloudMapBootstrapConfiguration(CloudMapProperties properties, ApplicationContext context) { + public CloudMapAutoConfiguration(CloudMapProperties properties, ApplicationContext context) { this.properties = properties; this.context = context; } diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapEventPublisherFactory.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapEventPublisherFactory.java new file mode 100644 index 000000000..a9f491426 --- /dev/null +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapEventPublisherFactory.java @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.awspring.cloud.autoconfigure.cloudmap; + +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class CloudMapEventPublisherFactory { + + @Bean + public ApplicationEventPublisher createListener() { + return new ApplicationEventPublisher() { + @Override + public void publishEvent(Object event) { + + } + }; + } +} diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapUtils.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapUtils.java index d30b6adec..1126773c8 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapUtils.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapUtils.java @@ -36,7 +36,7 @@ import org.springframework.cloud.client.ServiceInstance; import org.springframework.core.env.Environment; import org.springframework.util.StringUtils; -import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.client.RestTemplate; import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.ec2.Ec2Client; @@ -146,7 +146,7 @@ public class CloudMapUtils { final ObjectMapper JSON_MAPPER = new ObjectMapper(); - private final WebClient WEB_CLIENT = WebClient.create(); + private RestTemplate restTemplate; private Ec2Client ec2Client; @@ -157,7 +157,8 @@ public class CloudMapUtils { * @return map containing ip address and vpcid */ public Map getRegistrationAttributes() { - String deploymentPlatform = System.getenv(DEPLOYMENT_PLATFORM); + String deploymentPlatform = System.getenv(DEPLOYMENT_PLATFORM) == null ? System.getProperty(DEPLOYMENT_PLATFORM) + : System.getenv(DEPLOYMENT_PLATFORM); LOGGER.info("Deployment platform passed in {} ", deploymentPlatform); if (StringUtils.hasText(deploymentPlatform) && EKS.equalsIgnoreCase(deploymentPlatform.trim())) return getEksRegistrationAttributes(); @@ -544,7 +545,7 @@ private Map getEcsRegistrationAttributes() { .describeSubnets(DescribeSubnetsRequest.builder() .filters(Filter.builder().name("cidr-block").values(cidrBlock).build()).build()) .subnets().get(0).vpcId(); - LOGGER.info("IPv4Address {} - CIDR Block {} - VPC ID {}", ipv4Address, cidrBlock, vpcId); + LOGGER.info("IPv4Address {} - VPC ID {}", ipv4Address, vpcId); return getCloudMapAttributes(ipv4Address, vpcId); } catch (Exception e) { @@ -559,7 +560,7 @@ private Map getEcsRegistrationAttributes() { * @return response as string */ private String getUrlResponse(String url) { - return WEB_CLIENT.get().uri(url).retrieve().bodyToMono(String.class).block(); + return getRestTemplate().getForEntity(url, String.class).getBody(); } /** @@ -587,4 +588,22 @@ Ec2Client getEc2Client() { return ec2Client; } + /** + * Get Rest Template + * @return restTemplate + */ + RestTemplate getRestTemplate() { + if (restTemplate == null) { + restTemplate = new RestTemplate(); + } + return restTemplate; + } + + void setRestTemplate(RestTemplate restTemplate) { + this.restTemplate = restTemplate; + } + + void setEc2Client(Ec2Client ec2Client) { + this.ec2Client = ec2Client; + } } diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/discovery/CloudMapDiscoveryClient.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/discovery/CloudMapDiscoveryClient.java index 34f018b4d..9021a7d51 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/discovery/CloudMapDiscoveryClient.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/discovery/CloudMapDiscoveryClient.java @@ -55,7 +55,7 @@ public String description() { @Override public List getServices() { final List discoveryProperties = properties.getDiscovery().getDiscoveryList(); - if (discoveryProperties != null && !discoveryProperties.isEmpty()) { + if (!discoveryProperties.isEmpty()) { return UTILS.listServices(serviceDiscovery, discoveryProperties); } diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/discovery/package-info.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/discovery/package-info.java new file mode 100644 index 000000000..ee1ba4995 --- /dev/null +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/discovery/package-info.java @@ -0,0 +1,22 @@ +/* + * Copyright 2013-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Discovery client implementation for cloud map + */ +@org.springframework.lang.NonNullApi +@org.springframework.lang.NonNullFields +package io.awspring.cloud.autoconfigure.cloudmap.discovery; diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/package-info.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/package-info.java new file mode 100644 index 000000000..75e1b6e37 --- /dev/null +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2013-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Spring cloud Cloud map auto configuration and implementation classes + */ +package io.awspring.cloud.autoconfigure.cloudmap; diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/CloudMapProperties.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/CloudMapProperties.java index 9f245dd97..785b3af8b 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/CloudMapProperties.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/CloudMapProperties.java @@ -18,10 +18,8 @@ import io.awspring.cloud.autoconfigure.AwsClientProperties; import io.awspring.cloud.autoconfigure.cloudmap.properties.discovery.CloudMapDiscovery; import io.awspring.cloud.autoconfigure.cloudmap.properties.registration.CloudMapRegistryProperties; -import java.net.URI; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.EnvironmentAware; -import org.springframework.core.env.Environment; +import org.springframework.boot.context.properties.NestedConfigurationProperty; /** * POJO to capture all cloudmap integration parameters (both registry and discovery). @@ -30,46 +28,19 @@ * @since 3.0 */ @ConfigurationProperties(CloudMapProperties.CONFIG_PREFIX) -public class CloudMapProperties extends AwsClientProperties implements EnvironmentAware { +public class CloudMapProperties extends AwsClientProperties { /** * Default cloudmap prefix. */ public static final String CONFIG_PREFIX = "spring.cloud.aws.cloudmap"; + @NestedConfigurationProperty private CloudMapRegistryProperties registry; + @NestedConfigurationProperty private CloudMapDiscovery discovery; - private String region; - - /** - * Overrides the default endpoint. - */ - private URI endpoint; - - private boolean enabled; - - private String annotationBasePackage; - - private Environment environment; - - public String getAnnotationBasePackage() { - return this.annotationBasePackage; - } - - public void setAnnotationBasePackage(String annotationBasePackage) { - this.annotationBasePackage = annotationBasePackage; - } - - public String getRegion() { - return this.region; - } - - public void setRegion(String region) { - this.region = region; - } - public CloudMapRegistryProperties getRegistry() { return this.registry; } @@ -86,35 +57,10 @@ public void setDiscovery(CloudMapDiscovery discovery) { this.discovery = discovery; } - public boolean isEnabled() { - return this.enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public Environment getEnvironment() { - return environment; - } - - @Override - public void setEnvironment(Environment environment) { - this.environment = environment; - } - - public URI getEndpoint() { - return endpoint; - } - - public void setEndpoint(URI endpoint) { - this.endpoint = endpoint; - } - @Override public String toString() { - return "AwsCloudMapProperties{" + "registry=" + registry + ", discovery=" + discovery + ", region='" + region - + '\'' + ", enabled=" + enabled + ", annotationBasePackage='" + annotationBasePackage + '\'' + '}'; + return "AwsCloudMapProperties{" + "registry=" + registry + ", discovery=" + discovery + ", region='" + + getRegion() + "'}"; } } diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/discovery/CloudMapDiscovery.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/discovery/CloudMapDiscovery.java index 02e8e2780..5e91ad17d 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/discovery/CloudMapDiscovery.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/discovery/CloudMapDiscovery.java @@ -25,19 +25,8 @@ */ public class CloudMapDiscovery { - // Default to fail if discovery has failed - private boolean failFast = true; - private List discoveryList; - public boolean isFailFast() { - return this.failFast; - } - - public void setFailFast(boolean failFast) { - this.failFast = failFast; - } - public List getDiscoveryList() { return this.discoveryList; } @@ -48,7 +37,7 @@ public void setDiscoveryList(List discoveryList) { @Override public String toString() { - return "AwsCloudMapDiscovery{" + "failFast=" + failFast + ", discoveryList=" + discoveryList.toString() + '}'; + return "AwsCloudMapDiscovery{" + "discoveryList=" + discoveryList.toString() + '}'; } } diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/discovery/package-info.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/discovery/package-info.java new file mode 100644 index 000000000..1f9c8369c --- /dev/null +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/discovery/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2013-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Properties to capture all the discovery parameters + */ +package io.awspring.cloud.autoconfigure.cloudmap.properties.discovery; diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/package-info.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/package-info.java new file mode 100644 index 000000000..286e0aaea --- /dev/null +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2013-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Properties to capture cloud map both discovery and registration properties + */ +package io.awspring.cloud.autoconfigure.cloudmap.properties; diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/registration/package-info.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/registration/package-info.java new file mode 100644 index 000000000..83ec71459 --- /dev/null +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/properties/registration/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2013-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Registration client implementation for cloud map + */ +package io.awspring.cloud.autoconfigure.cloudmap.properties.registration; diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/registration/CloudMapAutoRegistration.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/registration/CloudMapAutoRegistration.java index a5c6017e9..2a650b533 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/registration/CloudMapAutoRegistration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/registration/CloudMapAutoRegistration.java @@ -17,6 +17,7 @@ import io.awspring.cloud.autoconfigure.cloudmap.CloudMapUtils; import io.awspring.cloud.autoconfigure.cloudmap.properties.registration.CloudMapRegistryProperties; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; @@ -29,6 +30,7 @@ import org.springframework.context.event.SmartApplicationListener; import org.springframework.core.Ordered; import org.springframework.core.env.Environment; +import org.springframework.lang.Nullable; import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryClient; public class CloudMapAutoRegistration @@ -44,9 +46,10 @@ public class CloudMapAutoRegistration private final CloudMapUtils UTILS = CloudMapUtils.getInstance(); + @Nullable private Environment environment; - private Map attributesMap; + private Map attributesMap = new HashMap<>(); public CloudMapAutoRegistration(ApplicationContext context, ServiceDiscoveryClient serviceDiscovery, CloudMapRegistryProperties properties) { @@ -97,7 +100,7 @@ public void start() { @Override public void stop() { - if (this.running.get() && attributesMap != null && attributesMap.containsKey(UTILS.SERVICE_INSTANCE_ID)) { + if (this.running.get() && !attributesMap.isEmpty() && attributesMap.containsKey(UTILS.SERVICE_INSTANCE_ID)) { UTILS.deregisterInstance(serviceDiscovery, attributesMap); this.running.set(false); } diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/registration/package-info.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/registration/package-info.java new file mode 100644 index 000000000..81c5e3ad3 --- /dev/null +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/cloudmap/registration/package-info.java @@ -0,0 +1,22 @@ +/* + * Copyright 2013-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Auto register implementation for cloud map + */ +@org.springframework.lang.NonNullApi +@org.springframework.lang.NonNullFields +package io.awspring.cloud.autoconfigure.cloudmap.registration; diff --git a/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/spring.factories index 7c17e2757..152a9da19 100644 --- a/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/spring.factories @@ -9,7 +9,7 @@ io.awspring.cloud.autoconfigure.s3.S3AutoConfiguration,\ io.awspring.cloud.autoconfigure.sns.SnsAutoConfiguration,\ io.awspring.cloud.autoconfigure.sqs.SqsAutoConfiguration,\ io.awspring.cloud.autoconfigure.dynamodb.DynamoDbAutoConfiguration,\ -io.awspring.cloud.autoconfigure.cloudmap.CloudMapBootstrapConfiguration +io.awspring.cloud.autoconfigure.cloudmap.CloudMapAutoConfiguration # ConfigData Location Resolvers org.springframework.boot.context.config.ConfigDataLocationResolver=\ diff --git a/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapRegisterServiceTest.java b/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapRegisterServiceTest.java index 5eb964d58..353bf2cdf 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapRegisterServiceTest.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapRegisterServiceTest.java @@ -20,6 +20,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import io.awspring.cloud.autoconfigure.cloudmap.properties.discovery.CloudMapDiscoveryProperties; import io.awspring.cloud.autoconfigure.cloudmap.properties.registration.CloudMapRegistryProperties; import io.awspring.cloud.autoconfigure.cloudmap.properties.registration.ServiceRegistration; import java.util.Collections; @@ -28,6 +29,12 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.core.env.Environment; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; +import software.amazon.awssdk.services.ec2.Ec2Client; +import software.amazon.awssdk.services.ec2.model.DescribeSubnetsRequest; +import software.amazon.awssdk.services.ec2.model.DescribeSubnetsResponse; +import software.amazon.awssdk.services.ec2.model.Subnet; import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryClient; import software.amazon.awssdk.services.servicediscovery.model.CreatePrivateDnsNamespaceRequest; import software.amazon.awssdk.services.servicediscovery.model.CreatePrivateDnsNamespaceResponse; @@ -57,12 +64,23 @@ */ public class CloudMapRegisterServiceTest { + private static final String DEPLOYMENT_PLATFORM = "DEPLOYMENT_PLATFORM"; + private static final String ECS = "ECS"; + private static final String EKS = "EKS"; private final ServiceDiscoveryClient serviceDiscovery = mock(ServiceDiscoveryClient.class); + private final Ec2Client ec2Client = mock(Ec2Client.class); private final CloudMapUtils cloudMapUtils = CloudMapUtils.getInstance(); + private final RestTemplate restTemplate = mock(RestTemplate.class); + private final Environment environment = mock(Environment.class); + public CloudMapRegisterServiceTest() { + cloudMapUtils.setEc2Client(ec2Client); + cloudMapUtils.setRestTemplate(restTemplate); + } + @Test public void cloudMapRegisterInstancesNameSpaceAndServiceExists() { final ListNamespacesResponse response = getListNamespacesResponse(); @@ -77,16 +95,25 @@ public void cloudMapRegisterInstancesNameSpaceAndServiceExists() { when(serviceDiscovery.getOperation((any(GetOperationRequest.class)))).thenReturn(operationResponse); when(serviceDiscovery.listServices(any(ListServicesRequest.class))).thenReturn(listServicesResponse); + + System.setProperty(DEPLOYMENT_PLATFORM, ECS); + when(restTemplate.getForEntity(CloudMapUtils.EC2_METADATA_URL + "/task", String.class)) + .thenReturn(ResponseEntity.ok(CloudMapTestConstants.ECS_REPONSE_JSON)); + when(ec2Client.describeSubnets(any(DescribeSubnetsRequest.class))).thenReturn( + DescribeSubnetsResponse.builder().subnets(Subnet.builder().vpcId("vpc-id").build()).build()); + assertThat(cloudMapUtils.registerInstance(serviceDiscovery, getProperties(), environment)).isNotEmpty(); } @Test - public void cloudMapRegisterInstanceWithNoNameSpace() { + public void cloudMapRegisterInstanceEcsWithNoNameSpace() { final ListNamespacesResponse listNamespacesResponse = getListNamespacesResponse(); final ListServicesResponse listServicesResponse = getListServicesResponse(); final RegisterInstanceResponse registerInstanceRequest = getRegisterInstanceResponse(); final GetOperationResponse operationResponse = getOperationResponse(); final CreatePrivateDnsNamespaceResponse createPrivateDnsNamespaceResponse = getCreatePrivateDnsNamespaceResponse(); + cloudMapUtils.setRestTemplate(restTemplate); + cloudMapUtils.setEc2Client(ec2Client); when(serviceDiscovery.listNamespaces(any(ListNamespacesRequest.class))).thenReturn( ListNamespacesResponse.builder().namespaces(Collections.emptyList()).build(), listNamespacesResponse); @@ -100,6 +127,50 @@ public void cloudMapRegisterInstanceWithNoNameSpace() { when(serviceDiscovery.getOperation((any(GetOperationRequest.class)))).thenReturn(operationResponse); when(serviceDiscovery.listServices(any(ListServicesRequest.class))).thenReturn(listServicesResponse); + + System.setProperty(DEPLOYMENT_PLATFORM, EKS); + when(restTemplate.getForEntity(String.format("%s/local-ipv4", CloudMapUtils.EC2_METADATA_URL), String.class)) + .thenReturn(ResponseEntity.ok("10.1.1.1")); + when(restTemplate.getForEntity(String.format("%s/network/interfaces/macs", CloudMapUtils.EC2_METADATA_URL), + String.class)).thenReturn(ResponseEntity.ok("MacId/Id")); + when(restTemplate.getForEntity( + String.format("%s/network/interfaces/macs/%s/vpc-id", CloudMapUtils.EC2_METADATA_URL, "MacId"), + String.class)).thenReturn(ResponseEntity.ok("vpcId")); + when(ec2Client.describeSubnets(any(DescribeSubnetsRequest.class))).thenReturn( + DescribeSubnetsResponse.builder().subnets(Subnet.builder().vpcId("vpc-id").build()).build()); + + assertThat(cloudMapUtils.registerInstance(serviceDiscovery, getProperties(), environment)).isNotEmpty(); + } + + @Test + public void cloudMapRegisterInstanceEksWithNoNameSpace() { + final ListNamespacesResponse listNamespacesResponse = getListNamespacesResponse(); + final ListServicesResponse listServicesResponse = getListServicesResponse(); + final RegisterInstanceResponse registerInstanceRequest = getRegisterInstanceResponse(); + final GetOperationResponse operationResponse = getOperationResponse(); + final CreatePrivateDnsNamespaceResponse createPrivateDnsNamespaceResponse = getCreatePrivateDnsNamespaceResponse(); + cloudMapUtils.setRestTemplate(restTemplate); + cloudMapUtils.setEc2Client(ec2Client); + + when(serviceDiscovery.listNamespaces(any(ListNamespacesRequest.class))).thenReturn( + ListNamespacesResponse.builder().namespaces(Collections.emptyList()).build(), listNamespacesResponse); + when(serviceDiscovery.createPrivateDnsNamespace(any(CreatePrivateDnsNamespaceRequest.class))) + .thenReturn(createPrivateDnsNamespaceResponse); + when(serviceDiscovery.getOperation((any(GetOperationRequest.class)))).thenReturn(operationResponse); + + when(serviceDiscovery.listServices(any(ListServicesRequest.class))).thenReturn(listServicesResponse); + when(serviceDiscovery.registerInstance((any(RegisterInstanceRequest.class)))) + .thenReturn(registerInstanceRequest); + when(serviceDiscovery.getOperation((any(GetOperationRequest.class)))).thenReturn(operationResponse); + + when(serviceDiscovery.listServices(any(ListServicesRequest.class))).thenReturn(listServicesResponse); + + System.setProperty(DEPLOYMENT_PLATFORM, ECS); + when(restTemplate.getForEntity(CloudMapUtils.EC2_METADATA_URL + "/task", String.class)) + .thenReturn(ResponseEntity.ok(CloudMapTestConstants.ECS_REPONSE_JSON)); + when(ec2Client.describeSubnets(any(DescribeSubnetsRequest.class))).thenReturn( + DescribeSubnetsResponse.builder().subnets(Subnet.builder().vpcId("vpc-id").build()).build()); + assertThat(cloudMapUtils.registerInstance(serviceDiscovery, getProperties(), environment)).isNotEmpty(); } @@ -123,9 +194,29 @@ public void cloudMapRegisterInstancesWithNoService() { .thenReturn(registerInstanceResponse); when(serviceDiscovery.getOperation((any(GetOperationRequest.class)))).thenReturn(operationResponse); + System.setProperty(DEPLOYMENT_PLATFORM, ECS); + when(restTemplate.getForEntity(CloudMapUtils.EC2_METADATA_URL + "/task", String.class)) + .thenReturn(ResponseEntity.ok(CloudMapTestConstants.ECS_REPONSE_JSON)); + when(ec2Client.describeSubnets(any(DescribeSubnetsRequest.class))).thenReturn( + DescribeSubnetsResponse.builder().subnets(Subnet.builder().vpcId("vpc-id").build()).build()); + assertThat(cloudMapUtils.registerInstance(serviceDiscovery, getProperties(), environment)).isNotEmpty(); } + @Test + public void listService() { + CloudMapDiscoveryProperties cloudMapDiscoveryProperties = new CloudMapDiscoveryProperties(); + cloudMapDiscoveryProperties.setService(CloudMapTestUtils.SERVICE); + cloudMapDiscoveryProperties.setNameSpace(CloudMapTestUtils.NAMESPACE); + final ListNamespacesResponse listNamespacesResponse = getListNamespacesResponse(); + final ListServicesResponse listServicesResponse = getListServicesResponse(); + + when(serviceDiscovery.listNamespaces(any(ListNamespacesRequest.class))).thenReturn(listNamespacesResponse); + when(serviceDiscovery.listServices(any(ListServicesRequest.class))).thenReturn(listServicesResponse); + + cloudMapUtils.listServices(serviceDiscovery, Collections.singletonList(cloudMapDiscoveryProperties)); + } + @Test public void deRegisterInstances() { try { @@ -173,12 +264,6 @@ private ListNamespacesResponse getListNamespacesResponse() { return ListNamespacesResponse.builder().namespaces(Collections.singleton(summary)).build(); } - private Map getAttributesMap() { - Map attributeMap = new HashMap<>(); - attributeMap.put(cloudMapUtils.IPV_4_ADDRESS, "10.1.1.23"); - return attributeMap; - } - private CloudMapRegistryProperties getProperties() { CloudMapRegistryProperties properties = new CloudMapRegistryProperties(); properties.setService(CloudMapTestUtils.SERVICE); diff --git a/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapTestConstants.java b/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapTestConstants.java new file mode 100644 index 000000000..d0b7810d6 --- /dev/null +++ b/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/cloudmap/CloudMapTestConstants.java @@ -0,0 +1,65 @@ +/* + * Copyright 2013-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.awspring.cloud.autoconfigure.cloudmap; + +/** + * Mock Responses from Ec2 meta-data endpoint + */ +public class CloudMapTestConstants { + /* + * Mock response + */ + public static final String ECS_REPONSE_JSON = "{\n" + " \"Cluster\": \"default\",\n" + + " \"TaskARN\": \"arn:aws:ecs:us-east-2:012345678910:task/9781c248-0edd-4cdb-9a93-f63cb662a5d3\",\n" + + " \"Family\": \"nginx\",\n" + " \"Revision\": \"5\",\n" + " \"DesiredStatus\": \"RUNNING\",\n" + + " \"KnownStatus\": \"RUNNING\",\n" + " \"Containers\": [\n" + " {\n" + + " \"DockerId\": \"731a0d6a3b4210e2448339bc7015aaa79bfe4fa256384f4102db86ef94cbbc4c\",\n" + + " \"Name\": \"~internal~ecs~pause\",\n" + + " \"DockerName\": \"ecs-nginx-5-internalecspause-acc699c0cbf2d6d11700\",\n" + + " \"Image\": \"amazon/amazon-ecs-pause:0.1.0\",\n" + " \"ImageID\": \"\",\n" + + " \"Labels\": {\n" + " \"com.amazonaws.ecs.cluster\": \"default\",\n" + + " \"com.amazonaws.ecs.container-name\": \"~internal~ecs~pause\",\n" + + " \"com.amazonaws.ecs.task-arn\": \"arn:aws:ecs:us-east-2:012345678910:task/9781c248-0edd-4cdb-9a93-f63cb662a5d3\",\n" + + " \"com.amazonaws.ecs.task-definition-family\": \"nginx\",\n" + + " \"com.amazonaws.ecs.task-definition-version\": \"5\"\n" + " },\n" + + " \"DesiredStatus\": \"RESOURCES_PROVISIONED\",\n" + + " \"KnownStatus\": \"RESOURCES_PROVISIONED\",\n" + " \"Limits\": {\n" + " \"CPU\": 0,\n" + + " \"Memory\": 0\n" + " },\n" + " \"CreatedAt\": \"2018-02-01T20:55:08.366329616Z\",\n" + + " \"StartedAt\": \"2018-02-01T20:55:09.058354915Z\",\n" + " \"Type\": \"CNI_PAUSE\",\n" + + " \"Networks\": [\n" + " {\n" + " \"NetworkMode\": \"awsvpc\",\n" + + " \"IPv4Addresses\": [\n" + " \"10.0.2.106\"\n" + " ],\n" + + " \"IPv4SubnetCIDRBlock\": [\n" + " \"10.0.2.106\"\n" + " ]\n" + + " }\n" + " ]\n" + " },\n" + " {\n" + + " \"DockerId\": \"43481a6ce4842eec8fe72fc28500c6b52edcc0917f105b83379f88cac1ff3946\",\n" + + " \"Name\": \"nginx-curl\",\n" + + " \"DockerName\": \"ecs-nginx-5-nginx-curl-ccccb9f49db0dfe0d901\",\n" + + " \"Image\": \"nrdlngr/nginx-curl\",\n" + + " \"ImageID\": \"sha256:2e00ae64383cfc865ba0a2ba37f61b50a120d2d9378559dcd458dc0de47bc165\",\n" + + " \"Labels\": {\n" + " \"com.amazonaws.ecs.cluster\": \"default\",\n" + + " \"com.amazonaws.ecs.container-name\": \"nginx-curl\",\n" + + " \"com.amazonaws.ecs.task-arn\": \"arn:aws:ecs:us-east-2:012345678910:task/9781c248-0edd-4cdb-9a93-f63cb662a5d3\",\n" + + " \"com.amazonaws.ecs.task-definition-family\": \"nginx\",\n" + + " \"com.amazonaws.ecs.task-definition-version\": \"5\"\n" + " },\n" + + " \"DesiredStatus\": \"RUNNING\",\n" + " \"KnownStatus\": \"RUNNING\",\n" + + " \"Limits\": {\n" + " \"CPU\": 512,\n" + " \"Memory\": 512\n" + " },\n" + + " \"CreatedAt\": \"2018-02-01T20:55:10.554941919Z\",\n" + + " \"StartedAt\": \"2018-02-01T20:55:11.064236631Z\",\n" + " \"Type\": \"NORMAL\",\n" + + " \"Networks\": [\n" + " {\n" + " \"NetworkMode\": \"awsvpc\",\n" + + " \"IPv4Addresses\": [\n" + " \"10.0.2.106\"\n" + " ]\n" + " }\n" + + " ]\n" + " }\n" + " ],\n" + " \"PullStartedAt\": \"2018-02-01T20:55:09.372495529Z\",\n" + + " \"PullStoppedAt\": \"2018-02-01T20:55:10.552018345Z\",\n" + " \"AvailabilityZone\": \"us-east-2b\"\n" + + "}"; +} diff --git a/spring-cloud-aws-cloudmap/pom.xml b/spring-cloud-aws-cloudmap/pom.xml index d9a955898..b92741f34 100644 --- a/spring-cloud-aws-cloudmap/pom.xml +++ b/spring-cloud-aws-cloudmap/pom.xml @@ -44,16 +44,6 @@ ec2 - - org.springframework - spring-web - - - - org.springframework - spring-webflux - - io.projectreactor.netty reactor-netty-http diff --git a/spring-cloud-aws-cloudmap/src/main/java/org/springframework/cloud/aws/cloudmap/exceptions/package-info.java b/spring-cloud-aws-cloudmap/src/main/java/org/springframework/cloud/aws/cloudmap/exceptions/package-info.java new file mode 100644 index 000000000..3c7422241 --- /dev/null +++ b/spring-cloud-aws-cloudmap/src/main/java/org/springframework/cloud/aws/cloudmap/exceptions/package-info.java @@ -0,0 +1,23 @@ +/* + * Copyright 2013-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * {@link org.springframework.boot.context.config.ConfigDataLoader} implementation for AWS CloudMap. + */ + +@org.springframework.lang.NonNullApi +@org.springframework.lang.NonNullFields +package org.springframework.cloud.aws.cloudmap.exceptions; diff --git a/spring-cloud-aws-s3-parent/spring-cloud-aws-s3-cross-region-client/src/main/java/io/awspring/cloud/s3/crossregion/AbstractCrossRegionS3Client.java b/spring-cloud-aws-s3-parent/spring-cloud-aws-s3-cross-region-client/src/main/java/io/awspring/cloud/s3/crossregion/AbstractCrossRegionS3Client.java index 309a0f877..0ce55c8df 100644 --- a/spring-cloud-aws-s3-parent/spring-cloud-aws-s3-cross-region-client/src/main/java/io/awspring/cloud/s3/crossregion/AbstractCrossRegionS3Client.java +++ b/spring-cloud-aws-s3-parent/spring-cloud-aws-s3-cross-region-client/src/main/java/io/awspring/cloud/s3/crossregion/AbstractCrossRegionS3Client.java @@ -16,753 +16,544 @@ package io.awspring.cloud.s3.crossregion; import java.util.function.Function; +import software.amazon.awssdk.services.s3.S3Client; import software.amazon.awssdk.awscore.exception.AwsServiceException; import software.amazon.awssdk.core.exception.SdkClientException; -import software.amazon.awssdk.services.s3.S3Client; abstract class AbstractCrossRegionS3Client implements S3Client { - abstract R executeInBucketRegion(String bucket, Function fn); - - abstract R executeInDefaultRegion(Function fn); - - @Override - public String serviceName() { - return S3Client.SERVICE_NAME; - } - - @Override - public software.amazon.awssdk.services.s3.model.AbortMultipartUploadResponse abortMultipartUpload( - software.amazon.awssdk.services.s3.model.AbortMultipartUploadRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.abortMultipartUpload(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.CompleteMultipartUploadResponse completeMultipartUpload( - software.amazon.awssdk.services.s3.model.CompleteMultipartUploadRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.completeMultipartUpload(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.CopyObjectResponse copyObject( - software.amazon.awssdk.services.s3.model.CopyObjectRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.copyObject(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.CreateBucketResponse createBucket( - software.amazon.awssdk.services.s3.model.CreateBucketRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.createBucket(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.CreateMultipartUploadResponse createMultipartUpload( - software.amazon.awssdk.services.s3.model.CreateMultipartUploadRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.createMultipartUpload(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeleteBucketResponse deleteBucket( - software.amazon.awssdk.services.s3.model.DeleteBucketRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucket(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeleteBucketAnalyticsConfigurationResponse deleteBucketAnalyticsConfiguration( - software.amazon.awssdk.services.s3.model.DeleteBucketAnalyticsConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketAnalyticsConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeleteBucketCorsResponse deleteBucketCors( - software.amazon.awssdk.services.s3.model.DeleteBucketCorsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketCors(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeleteBucketEncryptionResponse deleteBucketEncryption( - software.amazon.awssdk.services.s3.model.DeleteBucketEncryptionRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketEncryption(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeleteBucketIntelligentTieringConfigurationResponse deleteBucketIntelligentTieringConfiguration( - software.amazon.awssdk.services.s3.model.DeleteBucketIntelligentTieringConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketIntelligentTieringConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeleteBucketInventoryConfigurationResponse deleteBucketInventoryConfiguration( - software.amazon.awssdk.services.s3.model.DeleteBucketInventoryConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketInventoryConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeleteBucketLifecycleResponse deleteBucketLifecycle( - software.amazon.awssdk.services.s3.model.DeleteBucketLifecycleRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketLifecycle(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeleteBucketMetricsConfigurationResponse deleteBucketMetricsConfiguration( - software.amazon.awssdk.services.s3.model.DeleteBucketMetricsConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketMetricsConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeleteBucketOwnershipControlsResponse deleteBucketOwnershipControls( - software.amazon.awssdk.services.s3.model.DeleteBucketOwnershipControlsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketOwnershipControls(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeleteBucketPolicyResponse deleteBucketPolicy( - software.amazon.awssdk.services.s3.model.DeleteBucketPolicyRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketPolicy(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeleteBucketReplicationResponse deleteBucketReplication( - software.amazon.awssdk.services.s3.model.DeleteBucketReplicationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketReplication(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeleteBucketTaggingResponse deleteBucketTagging( - software.amazon.awssdk.services.s3.model.DeleteBucketTaggingRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketTagging(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeleteBucketWebsiteResponse deleteBucketWebsite( - software.amazon.awssdk.services.s3.model.DeleteBucketWebsiteRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketWebsite(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeleteObjectResponse deleteObject( - software.amazon.awssdk.services.s3.model.DeleteObjectRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteObject(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeleteObjectTaggingResponse deleteObjectTagging( - software.amazon.awssdk.services.s3.model.DeleteObjectTaggingRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteObjectTagging(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeleteObjectsResponse deleteObjects( - software.amazon.awssdk.services.s3.model.DeleteObjectsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteObjects(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.DeletePublicAccessBlockResponse deletePublicAccessBlock( - software.amazon.awssdk.services.s3.model.DeletePublicAccessBlockRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deletePublicAccessBlock(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketAccelerateConfigurationResponse getBucketAccelerateConfiguration( - software.amazon.awssdk.services.s3.model.GetBucketAccelerateConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketAccelerateConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketAclResponse getBucketAcl( - software.amazon.awssdk.services.s3.model.GetBucketAclRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketAcl(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketAnalyticsConfigurationResponse getBucketAnalyticsConfiguration( - software.amazon.awssdk.services.s3.model.GetBucketAnalyticsConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketAnalyticsConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketCorsResponse getBucketCors( - software.amazon.awssdk.services.s3.model.GetBucketCorsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketCors(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketEncryptionResponse getBucketEncryption( - software.amazon.awssdk.services.s3.model.GetBucketEncryptionRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketEncryption(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketIntelligentTieringConfigurationResponse getBucketIntelligentTieringConfiguration( - software.amazon.awssdk.services.s3.model.GetBucketIntelligentTieringConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketIntelligentTieringConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketInventoryConfigurationResponse getBucketInventoryConfiguration( - software.amazon.awssdk.services.s3.model.GetBucketInventoryConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketInventoryConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketLifecycleConfigurationResponse getBucketLifecycleConfiguration( - software.amazon.awssdk.services.s3.model.GetBucketLifecycleConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketLifecycleConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketLocationResponse getBucketLocation( - software.amazon.awssdk.services.s3.model.GetBucketLocationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketLocation(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketLoggingResponse getBucketLogging( - software.amazon.awssdk.services.s3.model.GetBucketLoggingRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketLogging(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketMetricsConfigurationResponse getBucketMetricsConfiguration( - software.amazon.awssdk.services.s3.model.GetBucketMetricsConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketMetricsConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketNotificationConfigurationResponse getBucketNotificationConfiguration( - software.amazon.awssdk.services.s3.model.GetBucketNotificationConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketNotificationConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketOwnershipControlsResponse getBucketOwnershipControls( - software.amazon.awssdk.services.s3.model.GetBucketOwnershipControlsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketOwnershipControls(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketPolicyResponse getBucketPolicy( - software.amazon.awssdk.services.s3.model.GetBucketPolicyRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketPolicy(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketPolicyStatusResponse getBucketPolicyStatus( - software.amazon.awssdk.services.s3.model.GetBucketPolicyStatusRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketPolicyStatus(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketReplicationResponse getBucketReplication( - software.amazon.awssdk.services.s3.model.GetBucketReplicationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketReplication(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketRequestPaymentResponse getBucketRequestPayment( - software.amazon.awssdk.services.s3.model.GetBucketRequestPaymentRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketRequestPayment(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketTaggingResponse getBucketTagging( - software.amazon.awssdk.services.s3.model.GetBucketTaggingRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketTagging(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketVersioningResponse getBucketVersioning( - software.amazon.awssdk.services.s3.model.GetBucketVersioningRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketVersioning(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetBucketWebsiteResponse getBucketWebsite( - software.amazon.awssdk.services.s3.model.GetBucketWebsiteRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketWebsite(p0)); - } - - @Override - public software.amazon.awssdk.core.ResponseInputStream getObject( - software.amazon.awssdk.services.s3.model.GetObjectRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObject(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetObjectResponse getObject( - software.amazon.awssdk.services.s3.model.GetObjectRequest p0, java.nio.file.Path p1) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObject(p0, p1)); - } - - @Override - public ReturnT getObject(software.amazon.awssdk.services.s3.model.GetObjectRequest p0, - software.amazon.awssdk.core.sync.ResponseTransformer p1) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObject(p0, p1)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetObjectAclResponse getObjectAcl( - software.amazon.awssdk.services.s3.model.GetObjectAclRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectAcl(p0)); - } - - @Override - public software.amazon.awssdk.core.ResponseBytes getObjectAsBytes( - software.amazon.awssdk.services.s3.model.GetObjectRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectAsBytes(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetObjectAttributesResponse getObjectAttributes( - software.amazon.awssdk.services.s3.model.GetObjectAttributesRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectAttributes(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetObjectLegalHoldResponse getObjectLegalHold( - software.amazon.awssdk.services.s3.model.GetObjectLegalHoldRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectLegalHold(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetObjectLockConfigurationResponse getObjectLockConfiguration( - software.amazon.awssdk.services.s3.model.GetObjectLockConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectLockConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetObjectRetentionResponse getObjectRetention( - software.amazon.awssdk.services.s3.model.GetObjectRetentionRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectRetention(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetObjectTaggingResponse getObjectTagging( - software.amazon.awssdk.services.s3.model.GetObjectTaggingRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectTagging(p0)); - } - - @Override - public software.amazon.awssdk.core.ResponseInputStream getObjectTorrent( - software.amazon.awssdk.services.s3.model.GetObjectTorrentRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectTorrent(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetObjectTorrentResponse getObjectTorrent( - software.amazon.awssdk.services.s3.model.GetObjectTorrentRequest p0, java.nio.file.Path p1) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectTorrent(p0, p1)); - } - - @Override - public ReturnT getObjectTorrent(software.amazon.awssdk.services.s3.model.GetObjectTorrentRequest p0, - software.amazon.awssdk.core.sync.ResponseTransformer p1) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectTorrent(p0, p1)); - } - - @Override - public software.amazon.awssdk.core.ResponseBytes getObjectTorrentAsBytes( - software.amazon.awssdk.services.s3.model.GetObjectTorrentRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectTorrentAsBytes(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.GetPublicAccessBlockResponse getPublicAccessBlock( - software.amazon.awssdk.services.s3.model.GetPublicAccessBlockRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getPublicAccessBlock(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.HeadBucketResponse headBucket( - software.amazon.awssdk.services.s3.model.HeadBucketRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.headBucket(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.HeadObjectResponse headObject( - software.amazon.awssdk.services.s3.model.HeadObjectRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.headObject(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.ListBucketAnalyticsConfigurationsResponse listBucketAnalyticsConfigurations( - software.amazon.awssdk.services.s3.model.ListBucketAnalyticsConfigurationsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listBucketAnalyticsConfigurations(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.ListBucketIntelligentTieringConfigurationsResponse listBucketIntelligentTieringConfigurations( - software.amazon.awssdk.services.s3.model.ListBucketIntelligentTieringConfigurationsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listBucketIntelligentTieringConfigurations(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.ListBucketInventoryConfigurationsResponse listBucketInventoryConfigurations( - software.amazon.awssdk.services.s3.model.ListBucketInventoryConfigurationsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listBucketInventoryConfigurations(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.ListBucketMetricsConfigurationsResponse listBucketMetricsConfigurations( - software.amazon.awssdk.services.s3.model.ListBucketMetricsConfigurationsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listBucketMetricsConfigurations(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.ListBucketsResponse listBuckets( - software.amazon.awssdk.services.s3.model.ListBucketsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInDefaultRegion(s3Client -> s3Client.listBuckets(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.ListMultipartUploadsResponse listMultipartUploads( - software.amazon.awssdk.services.s3.model.ListMultipartUploadsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listMultipartUploads(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.paginators.ListMultipartUploadsIterable listMultipartUploadsPaginator( - software.amazon.awssdk.services.s3.model.ListMultipartUploadsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listMultipartUploadsPaginator(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.ListObjectVersionsResponse listObjectVersions( - software.amazon.awssdk.services.s3.model.ListObjectVersionsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listObjectVersions(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.paginators.ListObjectVersionsIterable listObjectVersionsPaginator( - software.amazon.awssdk.services.s3.model.ListObjectVersionsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listObjectVersionsPaginator(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.ListObjectsResponse listObjects( - software.amazon.awssdk.services.s3.model.ListObjectsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listObjects(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.ListObjectsV2Response listObjectsV2( - software.amazon.awssdk.services.s3.model.ListObjectsV2Request p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listObjectsV2(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.paginators.ListObjectsV2Iterable listObjectsV2Paginator( - software.amazon.awssdk.services.s3.model.ListObjectsV2Request p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listObjectsV2Paginator(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.ListPartsResponse listParts( - software.amazon.awssdk.services.s3.model.ListPartsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listParts(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.paginators.ListPartsIterable listPartsPaginator( - software.amazon.awssdk.services.s3.model.ListPartsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listPartsPaginator(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketAccelerateConfigurationResponse putBucketAccelerateConfiguration( - software.amazon.awssdk.services.s3.model.PutBucketAccelerateConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketAccelerateConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketAclResponse putBucketAcl( - software.amazon.awssdk.services.s3.model.PutBucketAclRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketAcl(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketAnalyticsConfigurationResponse putBucketAnalyticsConfiguration( - software.amazon.awssdk.services.s3.model.PutBucketAnalyticsConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketAnalyticsConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketCorsResponse putBucketCors( - software.amazon.awssdk.services.s3.model.PutBucketCorsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketCors(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketEncryptionResponse putBucketEncryption( - software.amazon.awssdk.services.s3.model.PutBucketEncryptionRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketEncryption(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketIntelligentTieringConfigurationResponse putBucketIntelligentTieringConfiguration( - software.amazon.awssdk.services.s3.model.PutBucketIntelligentTieringConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketIntelligentTieringConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketInventoryConfigurationResponse putBucketInventoryConfiguration( - software.amazon.awssdk.services.s3.model.PutBucketInventoryConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketInventoryConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketLifecycleConfigurationResponse putBucketLifecycleConfiguration( - software.amazon.awssdk.services.s3.model.PutBucketLifecycleConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketLifecycleConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketLoggingResponse putBucketLogging( - software.amazon.awssdk.services.s3.model.PutBucketLoggingRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketLogging(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketMetricsConfigurationResponse putBucketMetricsConfiguration( - software.amazon.awssdk.services.s3.model.PutBucketMetricsConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketMetricsConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketNotificationConfigurationResponse putBucketNotificationConfiguration( - software.amazon.awssdk.services.s3.model.PutBucketNotificationConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketNotificationConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketOwnershipControlsResponse putBucketOwnershipControls( - software.amazon.awssdk.services.s3.model.PutBucketOwnershipControlsRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketOwnershipControls(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketPolicyResponse putBucketPolicy( - software.amazon.awssdk.services.s3.model.PutBucketPolicyRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketPolicy(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketReplicationResponse putBucketReplication( - software.amazon.awssdk.services.s3.model.PutBucketReplicationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketReplication(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketRequestPaymentResponse putBucketRequestPayment( - software.amazon.awssdk.services.s3.model.PutBucketRequestPaymentRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketRequestPayment(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketTaggingResponse putBucketTagging( - software.amazon.awssdk.services.s3.model.PutBucketTaggingRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketTagging(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketVersioningResponse putBucketVersioning( - software.amazon.awssdk.services.s3.model.PutBucketVersioningRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketVersioning(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutBucketWebsiteResponse putBucketWebsite( - software.amazon.awssdk.services.s3.model.PutBucketWebsiteRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketWebsite(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutObjectResponse putObject( - software.amazon.awssdk.services.s3.model.PutObjectRequest p0, java.nio.file.Path p1) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putObject(p0, p1)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutObjectResponse putObject( - software.amazon.awssdk.services.s3.model.PutObjectRequest p0, - software.amazon.awssdk.core.sync.RequestBody p1) throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putObject(p0, p1)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutObjectAclResponse putObjectAcl( - software.amazon.awssdk.services.s3.model.PutObjectAclRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putObjectAcl(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutObjectLegalHoldResponse putObjectLegalHold( - software.amazon.awssdk.services.s3.model.PutObjectLegalHoldRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putObjectLegalHold(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutObjectLockConfigurationResponse putObjectLockConfiguration( - software.amazon.awssdk.services.s3.model.PutObjectLockConfigurationRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putObjectLockConfiguration(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutObjectRetentionResponse putObjectRetention( - software.amazon.awssdk.services.s3.model.PutObjectRetentionRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putObjectRetention(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutObjectTaggingResponse putObjectTagging( - software.amazon.awssdk.services.s3.model.PutObjectTaggingRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putObjectTagging(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.PutPublicAccessBlockResponse putPublicAccessBlock( - software.amazon.awssdk.services.s3.model.PutPublicAccessBlockRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putPublicAccessBlock(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.RestoreObjectResponse restoreObject( - software.amazon.awssdk.services.s3.model.RestoreObjectRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.restoreObject(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.UploadPartResponse uploadPart( - software.amazon.awssdk.services.s3.model.UploadPartRequest p0, java.nio.file.Path p1) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.uploadPart(p0, p1)); - } - - @Override - public software.amazon.awssdk.services.s3.model.UploadPartResponse uploadPart( - software.amazon.awssdk.services.s3.model.UploadPartRequest p0, - software.amazon.awssdk.core.sync.RequestBody p1) throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.uploadPart(p0, p1)); - } - - @Override - public software.amazon.awssdk.services.s3.model.UploadPartCopyResponse uploadPartCopy( - software.amazon.awssdk.services.s3.model.UploadPartCopyRequest p0) - throws AwsServiceException, SdkClientException { - return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.uploadPartCopy(p0)); - } - - @Override - public software.amazon.awssdk.services.s3.model.WriteGetObjectResponseResponse writeGetObjectResponse( - software.amazon.awssdk.services.s3.model.WriteGetObjectResponseRequest p0, java.nio.file.Path p1) - throws AwsServiceException, SdkClientException { - return executeInDefaultRegion(s3Client -> s3Client.writeGetObjectResponse(p0, p1)); - } - - @Override - public software.amazon.awssdk.services.s3.model.WriteGetObjectResponseResponse writeGetObjectResponse( - software.amazon.awssdk.services.s3.model.WriteGetObjectResponseRequest p0, - software.amazon.awssdk.core.sync.RequestBody p1) throws AwsServiceException, SdkClientException { - return executeInDefaultRegion(s3Client -> s3Client.writeGetObjectResponse(p0, p1)); - } + abstract R executeInBucketRegion(String bucket, Function fn); + + abstract R executeInDefaultRegion(Function fn); + + @Override + public String serviceName() { + return S3Client.SERVICE_NAME; + } + + @Override + public software.amazon.awssdk.services.s3.model.AbortMultipartUploadResponse abortMultipartUpload(software.amazon.awssdk.services.s3.model.AbortMultipartUploadRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.abortMultipartUpload(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.CompleteMultipartUploadResponse completeMultipartUpload(software.amazon.awssdk.services.s3.model.CompleteMultipartUploadRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.completeMultipartUpload(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.CopyObjectResponse copyObject(software.amazon.awssdk.services.s3.model.CopyObjectRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.copyObject(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.CreateBucketResponse createBucket(software.amazon.awssdk.services.s3.model.CreateBucketRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.createBucket(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.CreateMultipartUploadResponse createMultipartUpload(software.amazon.awssdk.services.s3.model.CreateMultipartUploadRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.createMultipartUpload(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeleteBucketResponse deleteBucket(software.amazon.awssdk.services.s3.model.DeleteBucketRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucket(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeleteBucketAnalyticsConfigurationResponse deleteBucketAnalyticsConfiguration(software.amazon.awssdk.services.s3.model.DeleteBucketAnalyticsConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketAnalyticsConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeleteBucketCorsResponse deleteBucketCors(software.amazon.awssdk.services.s3.model.DeleteBucketCorsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketCors(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeleteBucketEncryptionResponse deleteBucketEncryption(software.amazon.awssdk.services.s3.model.DeleteBucketEncryptionRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketEncryption(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeleteBucketIntelligentTieringConfigurationResponse deleteBucketIntelligentTieringConfiguration(software.amazon.awssdk.services.s3.model.DeleteBucketIntelligentTieringConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketIntelligentTieringConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeleteBucketInventoryConfigurationResponse deleteBucketInventoryConfiguration(software.amazon.awssdk.services.s3.model.DeleteBucketInventoryConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketInventoryConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeleteBucketLifecycleResponse deleteBucketLifecycle(software.amazon.awssdk.services.s3.model.DeleteBucketLifecycleRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketLifecycle(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeleteBucketMetricsConfigurationResponse deleteBucketMetricsConfiguration(software.amazon.awssdk.services.s3.model.DeleteBucketMetricsConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketMetricsConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeleteBucketOwnershipControlsResponse deleteBucketOwnershipControls(software.amazon.awssdk.services.s3.model.DeleteBucketOwnershipControlsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketOwnershipControls(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeleteBucketPolicyResponse deleteBucketPolicy(software.amazon.awssdk.services.s3.model.DeleteBucketPolicyRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketPolicy(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeleteBucketReplicationResponse deleteBucketReplication(software.amazon.awssdk.services.s3.model.DeleteBucketReplicationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketReplication(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeleteBucketTaggingResponse deleteBucketTagging(software.amazon.awssdk.services.s3.model.DeleteBucketTaggingRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketTagging(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeleteBucketWebsiteResponse deleteBucketWebsite(software.amazon.awssdk.services.s3.model.DeleteBucketWebsiteRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteBucketWebsite(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeleteObjectResponse deleteObject(software.amazon.awssdk.services.s3.model.DeleteObjectRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteObject(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeleteObjectTaggingResponse deleteObjectTagging(software.amazon.awssdk.services.s3.model.DeleteObjectTaggingRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteObjectTagging(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeleteObjectsResponse deleteObjects(software.amazon.awssdk.services.s3.model.DeleteObjectsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deleteObjects(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.DeletePublicAccessBlockResponse deletePublicAccessBlock(software.amazon.awssdk.services.s3.model.DeletePublicAccessBlockRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.deletePublicAccessBlock(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketAccelerateConfigurationResponse getBucketAccelerateConfiguration(software.amazon.awssdk.services.s3.model.GetBucketAccelerateConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketAccelerateConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketAclResponse getBucketAcl(software.amazon.awssdk.services.s3.model.GetBucketAclRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketAcl(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketAnalyticsConfigurationResponse getBucketAnalyticsConfiguration(software.amazon.awssdk.services.s3.model.GetBucketAnalyticsConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketAnalyticsConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketCorsResponse getBucketCors(software.amazon.awssdk.services.s3.model.GetBucketCorsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketCors(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketEncryptionResponse getBucketEncryption(software.amazon.awssdk.services.s3.model.GetBucketEncryptionRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketEncryption(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketIntelligentTieringConfigurationResponse getBucketIntelligentTieringConfiguration(software.amazon.awssdk.services.s3.model.GetBucketIntelligentTieringConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketIntelligentTieringConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketInventoryConfigurationResponse getBucketInventoryConfiguration(software.amazon.awssdk.services.s3.model.GetBucketInventoryConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketInventoryConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketLifecycleConfigurationResponse getBucketLifecycleConfiguration(software.amazon.awssdk.services.s3.model.GetBucketLifecycleConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketLifecycleConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketLocationResponse getBucketLocation(software.amazon.awssdk.services.s3.model.GetBucketLocationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketLocation(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketLoggingResponse getBucketLogging(software.amazon.awssdk.services.s3.model.GetBucketLoggingRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketLogging(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketMetricsConfigurationResponse getBucketMetricsConfiguration(software.amazon.awssdk.services.s3.model.GetBucketMetricsConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketMetricsConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketNotificationConfigurationResponse getBucketNotificationConfiguration(software.amazon.awssdk.services.s3.model.GetBucketNotificationConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketNotificationConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketOwnershipControlsResponse getBucketOwnershipControls(software.amazon.awssdk.services.s3.model.GetBucketOwnershipControlsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketOwnershipControls(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketPolicyResponse getBucketPolicy(software.amazon.awssdk.services.s3.model.GetBucketPolicyRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketPolicy(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketPolicyStatusResponse getBucketPolicyStatus(software.amazon.awssdk.services.s3.model.GetBucketPolicyStatusRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketPolicyStatus(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketReplicationResponse getBucketReplication(software.amazon.awssdk.services.s3.model.GetBucketReplicationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketReplication(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketRequestPaymentResponse getBucketRequestPayment(software.amazon.awssdk.services.s3.model.GetBucketRequestPaymentRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketRequestPayment(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketTaggingResponse getBucketTagging(software.amazon.awssdk.services.s3.model.GetBucketTaggingRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketTagging(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketVersioningResponse getBucketVersioning(software.amazon.awssdk.services.s3.model.GetBucketVersioningRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketVersioning(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetBucketWebsiteResponse getBucketWebsite(software.amazon.awssdk.services.s3.model.GetBucketWebsiteRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getBucketWebsite(p0)); + } + + @Override + public software.amazon.awssdk.core.ResponseInputStream getObject(software.amazon.awssdk.services.s3.model.GetObjectRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObject(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetObjectResponse getObject(software.amazon.awssdk.services.s3.model.GetObjectRequest p0, java.nio.file.Path p1) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObject(p0, p1)); + } + + @Override + public ReturnT getObject(software.amazon.awssdk.services.s3.model.GetObjectRequest p0, software.amazon.awssdk.core.sync.ResponseTransformer p1) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObject(p0, p1)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetObjectAclResponse getObjectAcl(software.amazon.awssdk.services.s3.model.GetObjectAclRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectAcl(p0)); + } + + @Override + public software.amazon.awssdk.core.ResponseBytes getObjectAsBytes(software.amazon.awssdk.services.s3.model.GetObjectRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectAsBytes(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetObjectAttributesResponse getObjectAttributes(software.amazon.awssdk.services.s3.model.GetObjectAttributesRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectAttributes(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetObjectLegalHoldResponse getObjectLegalHold(software.amazon.awssdk.services.s3.model.GetObjectLegalHoldRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectLegalHold(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetObjectLockConfigurationResponse getObjectLockConfiguration(software.amazon.awssdk.services.s3.model.GetObjectLockConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectLockConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetObjectRetentionResponse getObjectRetention(software.amazon.awssdk.services.s3.model.GetObjectRetentionRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectRetention(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetObjectTaggingResponse getObjectTagging(software.amazon.awssdk.services.s3.model.GetObjectTaggingRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectTagging(p0)); + } + + @Override + public software.amazon.awssdk.core.ResponseInputStream getObjectTorrent(software.amazon.awssdk.services.s3.model.GetObjectTorrentRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectTorrent(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetObjectTorrentResponse getObjectTorrent(software.amazon.awssdk.services.s3.model.GetObjectTorrentRequest p0, java.nio.file.Path p1) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectTorrent(p0, p1)); + } + + @Override + public ReturnT getObjectTorrent(software.amazon.awssdk.services.s3.model.GetObjectTorrentRequest p0, software.amazon.awssdk.core.sync.ResponseTransformer p1) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectTorrent(p0, p1)); + } + + @Override + public software.amazon.awssdk.core.ResponseBytes getObjectTorrentAsBytes(software.amazon.awssdk.services.s3.model.GetObjectTorrentRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getObjectTorrentAsBytes(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.GetPublicAccessBlockResponse getPublicAccessBlock(software.amazon.awssdk.services.s3.model.GetPublicAccessBlockRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.getPublicAccessBlock(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.HeadBucketResponse headBucket(software.amazon.awssdk.services.s3.model.HeadBucketRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.headBucket(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.HeadObjectResponse headObject(software.amazon.awssdk.services.s3.model.HeadObjectRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.headObject(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.ListBucketAnalyticsConfigurationsResponse listBucketAnalyticsConfigurations(software.amazon.awssdk.services.s3.model.ListBucketAnalyticsConfigurationsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listBucketAnalyticsConfigurations(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.ListBucketIntelligentTieringConfigurationsResponse listBucketIntelligentTieringConfigurations(software.amazon.awssdk.services.s3.model.ListBucketIntelligentTieringConfigurationsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listBucketIntelligentTieringConfigurations(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.ListBucketInventoryConfigurationsResponse listBucketInventoryConfigurations(software.amazon.awssdk.services.s3.model.ListBucketInventoryConfigurationsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listBucketInventoryConfigurations(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.ListBucketMetricsConfigurationsResponse listBucketMetricsConfigurations(software.amazon.awssdk.services.s3.model.ListBucketMetricsConfigurationsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listBucketMetricsConfigurations(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.ListBucketsResponse listBuckets(software.amazon.awssdk.services.s3.model.ListBucketsRequest p0) throws AwsServiceException, SdkClientException { + return executeInDefaultRegion(s3Client -> s3Client.listBuckets(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.ListMultipartUploadsResponse listMultipartUploads(software.amazon.awssdk.services.s3.model.ListMultipartUploadsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listMultipartUploads(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.paginators.ListMultipartUploadsIterable listMultipartUploadsPaginator(software.amazon.awssdk.services.s3.model.ListMultipartUploadsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listMultipartUploadsPaginator(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.ListObjectVersionsResponse listObjectVersions(software.amazon.awssdk.services.s3.model.ListObjectVersionsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listObjectVersions(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.paginators.ListObjectVersionsIterable listObjectVersionsPaginator(software.amazon.awssdk.services.s3.model.ListObjectVersionsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listObjectVersionsPaginator(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.ListObjectsResponse listObjects(software.amazon.awssdk.services.s3.model.ListObjectsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listObjects(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.ListObjectsV2Response listObjectsV2(software.amazon.awssdk.services.s3.model.ListObjectsV2Request p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listObjectsV2(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.paginators.ListObjectsV2Iterable listObjectsV2Paginator(software.amazon.awssdk.services.s3.model.ListObjectsV2Request p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listObjectsV2Paginator(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.ListPartsResponse listParts(software.amazon.awssdk.services.s3.model.ListPartsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listParts(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.paginators.ListPartsIterable listPartsPaginator(software.amazon.awssdk.services.s3.model.ListPartsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.listPartsPaginator(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketAccelerateConfigurationResponse putBucketAccelerateConfiguration(software.amazon.awssdk.services.s3.model.PutBucketAccelerateConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketAccelerateConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketAclResponse putBucketAcl(software.amazon.awssdk.services.s3.model.PutBucketAclRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketAcl(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketAnalyticsConfigurationResponse putBucketAnalyticsConfiguration(software.amazon.awssdk.services.s3.model.PutBucketAnalyticsConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketAnalyticsConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketCorsResponse putBucketCors(software.amazon.awssdk.services.s3.model.PutBucketCorsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketCors(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketEncryptionResponse putBucketEncryption(software.amazon.awssdk.services.s3.model.PutBucketEncryptionRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketEncryption(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketIntelligentTieringConfigurationResponse putBucketIntelligentTieringConfiguration(software.amazon.awssdk.services.s3.model.PutBucketIntelligentTieringConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketIntelligentTieringConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketInventoryConfigurationResponse putBucketInventoryConfiguration(software.amazon.awssdk.services.s3.model.PutBucketInventoryConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketInventoryConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketLifecycleConfigurationResponse putBucketLifecycleConfiguration(software.amazon.awssdk.services.s3.model.PutBucketLifecycleConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketLifecycleConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketLoggingResponse putBucketLogging(software.amazon.awssdk.services.s3.model.PutBucketLoggingRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketLogging(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketMetricsConfigurationResponse putBucketMetricsConfiguration(software.amazon.awssdk.services.s3.model.PutBucketMetricsConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketMetricsConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketNotificationConfigurationResponse putBucketNotificationConfiguration(software.amazon.awssdk.services.s3.model.PutBucketNotificationConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketNotificationConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketOwnershipControlsResponse putBucketOwnershipControls(software.amazon.awssdk.services.s3.model.PutBucketOwnershipControlsRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketOwnershipControls(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketPolicyResponse putBucketPolicy(software.amazon.awssdk.services.s3.model.PutBucketPolicyRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketPolicy(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketReplicationResponse putBucketReplication(software.amazon.awssdk.services.s3.model.PutBucketReplicationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketReplication(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketRequestPaymentResponse putBucketRequestPayment(software.amazon.awssdk.services.s3.model.PutBucketRequestPaymentRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketRequestPayment(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketTaggingResponse putBucketTagging(software.amazon.awssdk.services.s3.model.PutBucketTaggingRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketTagging(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketVersioningResponse putBucketVersioning(software.amazon.awssdk.services.s3.model.PutBucketVersioningRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketVersioning(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutBucketWebsiteResponse putBucketWebsite(software.amazon.awssdk.services.s3.model.PutBucketWebsiteRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putBucketWebsite(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutObjectResponse putObject(software.amazon.awssdk.services.s3.model.PutObjectRequest p0, java.nio.file.Path p1) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putObject(p0, p1)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutObjectResponse putObject(software.amazon.awssdk.services.s3.model.PutObjectRequest p0, software.amazon.awssdk.core.sync.RequestBody p1) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putObject(p0, p1)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutObjectAclResponse putObjectAcl(software.amazon.awssdk.services.s3.model.PutObjectAclRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putObjectAcl(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutObjectLegalHoldResponse putObjectLegalHold(software.amazon.awssdk.services.s3.model.PutObjectLegalHoldRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putObjectLegalHold(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutObjectLockConfigurationResponse putObjectLockConfiguration(software.amazon.awssdk.services.s3.model.PutObjectLockConfigurationRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putObjectLockConfiguration(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutObjectRetentionResponse putObjectRetention(software.amazon.awssdk.services.s3.model.PutObjectRetentionRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putObjectRetention(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutObjectTaggingResponse putObjectTagging(software.amazon.awssdk.services.s3.model.PutObjectTaggingRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putObjectTagging(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.PutPublicAccessBlockResponse putPublicAccessBlock(software.amazon.awssdk.services.s3.model.PutPublicAccessBlockRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.putPublicAccessBlock(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.RestoreObjectResponse restoreObject(software.amazon.awssdk.services.s3.model.RestoreObjectRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.restoreObject(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.UploadPartResponse uploadPart(software.amazon.awssdk.services.s3.model.UploadPartRequest p0, java.nio.file.Path p1) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.uploadPart(p0, p1)); + } + + @Override + public software.amazon.awssdk.services.s3.model.UploadPartResponse uploadPart(software.amazon.awssdk.services.s3.model.UploadPartRequest p0, software.amazon.awssdk.core.sync.RequestBody p1) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.uploadPart(p0, p1)); + } + + @Override + public software.amazon.awssdk.services.s3.model.UploadPartCopyResponse uploadPartCopy(software.amazon.awssdk.services.s3.model.UploadPartCopyRequest p0) throws AwsServiceException, SdkClientException { + return executeInBucketRegion(p0.bucket(), s3Client -> s3Client.uploadPartCopy(p0)); + } + + @Override + public software.amazon.awssdk.services.s3.model.WriteGetObjectResponseResponse writeGetObjectResponse(software.amazon.awssdk.services.s3.model.WriteGetObjectResponseRequest p0, java.nio.file.Path p1) throws AwsServiceException, SdkClientException { + return executeInDefaultRegion(s3Client -> s3Client.writeGetObjectResponse(p0, p1)); + } + + @Override + public software.amazon.awssdk.services.s3.model.WriteGetObjectResponseResponse writeGetObjectResponse(software.amazon.awssdk.services.s3.model.WriteGetObjectResponseRequest p0, software.amazon.awssdk.core.sync.RequestBody p1) throws AwsServiceException, SdkClientException { + return executeInDefaultRegion(s3Client -> s3Client.writeGetObjectResponse(p0, p1)); + } } + diff --git a/spring-cloud-aws-samples/spring-cloud-aws-cloud-map-sample/Dockerfile b/spring-cloud-aws-samples/spring-cloud-aws-cloud-map-sample/Dockerfile new file mode 100644 index 000000000..ef95ad6e1 --- /dev/null +++ b/spring-cloud-aws-samples/spring-cloud-aws-cloud-map-sample/Dockerfile @@ -0,0 +1,5 @@ +FROM amazoncorretto:11 +ARG JAR_FILE=target/spring-cloud-aws-cloud-map-sample-3.0.0-SNAPSHOT.jar +COPY ${JAR_FILE} app.jar +ENTRYPOINT ["java","-jar","/app.jar"] +EXPOSE 8080 diff --git a/spring-cloud-aws-samples/spring-cloud-aws-cloud-map-sample/README.md b/spring-cloud-aws-samples/spring-cloud-aws-cloud-map-sample/README.md new file mode 100644 index 000000000..7007910b2 --- /dev/null +++ b/spring-cloud-aws-samples/spring-cloud-aws-cloud-map-sample/README.md @@ -0,0 +1,255 @@ +# Spring Cloud AWS Cloud Map Sample + +Here is a step by step guide to run the sample application. + +---- + +## Prerequisites + +* Active internet connection +* Java 8 or above +* AWS credentials configured in `~/.aws/credentials` or as environment variables (see [AWS SDK documentation](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html)) +* Docker installed + +## Running the sample + +* Build the sample application + +```bash +mvn clean install +``` + +* Run a docker build to create a docker image using the `Dockerfile` defined in the root directory of this sample project: + +```bash +docker build -t aws-samples-cloudmap . +``` + +* Create a ECS Cluster using AWS CLI: + +```bash +aws ecs create-cluster --cluster-name cloudmap-sample +``` + +* Create a ECR repository using AWS CLI: + +```bash +aws ecr create-repository --repository-name cloudmap-sample +``` + +* Login to ECR, tag the docker image and push it to ECR: + +```bash +$(aws ecr get-login --no-include-email --region us-east-1) +docker tag aws-samples-cloudmap:latest .dkr.ecr.us-east-1.amazonaws.com/cloudmap-sample:latest +docker push .dkr.ecr.us-east-1.amazonaws.com/cloudmap-sample:latest +``` + +* Create a IAM role for ECS task execution: + +```bash +aws iam create-role --role-name ecsTaskExecutionRole --assume-role-policy-document file://task-execution-assume-role.json +``` + +**task-execution-assume-role.json** + +```json +{ + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + }, + "Action": "sts:AssumeRole" + } + ] +} +``` + +* Attach the following IAM policy to the role created in the previous step: + +```bash +aws iam put-role-policy --role-name ecsTaskExecutionRole --policy-name ecsTaskExecutionRole --policy-document file://task-execution-role-policy.json +``` + +**task-execution-role-policy.json** + +```json +{ + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Resource": "arn:aws:logs:*:*:*" + }, + { + "Effect": "Allow", + "Action": [ + "ecr:GetAuthorizationToken", + "ecr:BatchCheckLayerAvailability", + "ecr:GetDownloadUrlForLayer", + "ecr:BatchGetImage", + "ecr:DescribeRepositories" + ], + "Resource": "*" + } + ] +} +``` + +* Create a ECS Task role: + +```bash +aws iam create-role --role-name ecsTaskRole --assume-role-policy-document file://task-assume-role.json +``` + +**task-assume-role.json** + +```json +{ + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + }, + "Action": "sts:AssumeRole" + } + ] +} +``` + +* Attach the following IAM policy to the role created in the previous step: + +```bash +aws iam put-role-policy --role-name ecsTaskRole --policy-name ecsTaskRole --policy-document file://task-role-policy.json +``` + +**task-role-policy.json** + +```json +{ + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "servicediscovery:CreateService", + "servicediscovery:DeleteService", + "servicediscovery:GetService", + "servicediscovery:ListInstances", + "servicediscovery:ListNamespaces", + "servicediscovery:ListServices", + "servicediscovery:RegisterInstance", + "servicediscovery:DeregisterInstance", + "servicediscovery:ListOperations", + "servicediscovery:GetOperation" + ], + "Resource": "*" + } + ] +} +``` + +* Create a Task Definition using AWS CLI: + +```bash +aws ecs register-task-definition --name cloudmap-sample-definition --cli-input-json file://task-definition.json +``` + +**Task definition file** + +```json +{ + "executionRoleArn": "arn:aws:iam:::role/ecsTaskExecutionRole", + "containerDefinitions": [ + { + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-group": "/ecs/CloudMap", + "awslogs-region": "us-east-1", + "awslogs-stream-prefix": "ecs" + } + }, + "cpu": 0, + "environment": [ + { + "name": "DEPLOYMENT_PLATFORM", + "value": "ECS" + } + ], + "image": ".dkr.ecr.us-east-1.amazonaws.com/cloudmap-sample:latest", + "name": "mainContainer" + } + ], + "memory": "7168", + "taskRoleArn": "arn:aws:iam:::role/ecsTaskRole", + "family": "CloudMap", + "requiresCompatibilities": [ + "FARGATE" + ], + "networkMode": "awsvpc", + "runtimePlatform": { + "operatingSystemFamily": "LINUX", + }, + "cpu": "2048", +} +``` + +* Run the task using AWS CLI: + +```bash +aws ecs run-task --cluster cloudmap-sample --task-definition cloudmap-sample-definition --launch-type FARGATE --network-configuration "awsvpcConfiguration={subnets=[],securityGroups=[],assignPublicIp=ENABLED}" +``` + +## Verify Cloud Map service registration in AWS console + +* Login to AWS console and navigate to Cloud Map service. You should see a namespace (`a-namespace`) and a service (`a-service`) created. Under the service, you should see a instance registered with the IP address of the container running in ECS. + +## Clean up + +* Stop the task using AWS CLI: + +```bash +aws ecs stop-task --cluster cloudmap-sample --task +``` + +* Delete the task definition using AWS CLI: + +```bash +aws ecs deregister-task-definition --task-definition cloudmap-sample-definition +``` + +* Delete the ECS cluster using AWS CLI: + +```bash +aws ecs delete-cluster --cluster cloudmap-sample +``` + +* Detach the associated policies + +```bash +aws iam detach-role-policy --role-name ecsTaskExecutionRole --policy-arn arn:aws:iam:::policy/ecsTaskExecutionRole +aws iam detach-role-policy --role-name ecsTaskRole --policy-arn arn:aws:iam:::policy/service-role/AmazonECSTaskExecutionRolePolicy +``` + +* Delete the IAM role for ECS task execution using AWS CLI: + +```bash +aws iam delete-role --role-name ecsTaskExecutionRole +aws iam delete-role --role-name ecsTaskRole +``` + +* Delete ECR repository using AWS CLI: + +```bash +aws ecr delete-repository --repository-name cloudmap-sample --force +``` \ No newline at end of file diff --git a/spring-cloud-aws-samples/spring-cloud-aws-cloud-map-sample/src/main/resources/application.properties b/spring-cloud-aws-samples/spring-cloud-aws-cloud-map-sample/src/main/resources/application.properties index 15693f6b4..842630ce9 100644 --- a/spring-cloud-aws-samples/spring-cloud-aws-cloud-map-sample/src/main/resources/application.properties +++ b/spring-cloud-aws-samples/spring-cloud-aws-cloud-map-sample/src/main/resources/application.properties @@ -1,2 +1,13 @@ -# importing cloudmap configuration files -spring.config.import=bootstrap.properties +spring.cloud.aws.cloudmap.enabled=true +spring.application.name=cloudmap-namespace-here + +# Discover existing cloudmap instances +spring.cloud.aws.cloudmap.discovery.discoveryList[0].service=a-service +spring.cloud.aws.cloudmap.discovery.discoveryList[0].nameSpace=a-namespace + +# Register new instance + +spring.cloud.aws.cloudmap.registry.description=Namespace for sample cloudmap registry service +spring.cloud.aws.cloudmap.registry.port=80 +spring.cloud.aws.cloudmap.registry.service=a-service +spring.cloud.aws.cloudmap.registry.nameSpace=a-namespace diff --git a/spring-cloud-aws-samples/spring-cloud-aws-cloud-map-sample/src/main/resources/bootstrap.properties b/spring-cloud-aws-samples/spring-cloud-aws-cloud-map-sample/src/main/resources/bootstrap.properties index 8c5a60d85..88533696b 100644 --- a/spring-cloud-aws-samples/spring-cloud-aws-cloud-map-sample/src/main/resources/bootstrap.properties +++ b/spring-cloud-aws-samples/spring-cloud-aws-cloud-map-sample/src/main/resources/bootstrap.properties @@ -3,7 +3,6 @@ spring.cloud.aws.cloudmap.enabled=true spring.application.name=cloudmap-namespace-here # Discover existing cloudmap instances -spring.cloud.aws.cloudmap.discovery.failFast=false spring.cloud.aws.cloudmap.discovery.discoveryList[0].service=a-service spring.cloud.aws.cloudmap.discovery.discoveryList[0].nameSpace=a-namespace