> For the complete documentation index, see [llms.txt](https://xu-min-chang.gitbook.io/caster-develop-note/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xu-min-chang.gitbook.io/caster-develop-note/java/cloud-platform/ovhcloud/config.md).

# Config

OVH 文件上顯示說可以透過AWS S3 API 去使用，這樣就是可以直接使用AWS S3 Java SDK 去做認證並且對容器進行操作，就此開始了奇幻冒險.....

### 如何取得Key

<figure><img src="/files/59PaQ9w18JCnGwbaGBkI" alt=""><figcaption><p>首先找到User &#x26; Roles 這邊</p></figcaption></figure>

<figure><img src="/files/to3JylLCUQ88j62ewzht" alt=""><figcaption><p>生成S3 憑證Key</p></figcaption></figure>

<figure><img src="/files/YabGSCCPKFb2X6im07k7" alt=""><figcaption><p>再自行複製下來</p></figcaption></figure>

<figure><img src="/files/lmiRbDacczhrRCposLlo" alt=""><figcaption><p>LocationCode List</p></figcaption></figure>

### SDK V1

```java
@Configuration
public class AWSS3Config {

	@Value("${custom.aws.accessKey}")
	private String accessKey;

	@Value("${custom.aws.secretKey}")
	private String secretKey;

	@Value("${custom.aws.area}")
	private String area;
	
	@Bean
	public AmazonS3 createAWSS3Client() {
		AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

		//set-up the client
		// LocationCode 在建立 object container 時選擇區域時那邊的清單. 用縮寫(Ps.大小寫似乎都可以使用) Ex.Beauharnois(BHS) -> BHS
		AmazonS3 s3client = AmazonS3ClientBuilder
				.standard()
				.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("https://s3.{LocationCode}.cloud.ovh.net", "{LocationCode}"))
				.withCredentials(new AWSStaticCredentialsProvider(credentials))
				.build();
		return s3client;
	}
}
```

### SDK V2

```java
@Configuration
public class AWSS3Config {
	@Value("${custom.aws.accessKey}")
	private String accessKey;
	@Value("${custom.aws.secretKey}")
	private String secretKey;
	@Bean
	public S3Client createAWSS3Client() {
		AwsBasicCredentials awsCreds = AwsBasicCredentials.create(accessKey, secretKey);
		return S3Client.builder()
				.endpointOverride(new URI("https://s3.{LocationCode}.cloud.ovh.net"))
				.region(Region.of("{LocationCode}"))
				.credentialsProvider(StaticCredentialsProvider.create(awsCreds)).build();
	}
}
```
