# Config

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

### 如何取得Key

<figure><img src="https://1934262382-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRmnDr9RXeSmhkUmaUsX7%2Fuploads%2FG0gOtTRHd5csse4qaAnR%2F%E6%88%AA%E5%9C%96%202022-12-23%20%E4%B8%8B%E5%8D%883.05.55.png?alt=media&#x26;token=a08d70bb-01fb-4fa3-8b57-89299ee5a572" alt=""><figcaption><p>首先找到User &#x26; Roles 這邊</p></figcaption></figure>

<figure><img src="https://1934262382-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRmnDr9RXeSmhkUmaUsX7%2Fuploads%2FGRPXGJ2bD4kZMulV53XY%2F%E6%88%AA%E5%9C%96%202022-12-23%20%E4%B8%8B%E5%8D%883.07.56.png?alt=media&#x26;token=472193da-97fc-4c68-99c0-bd17a925ff4b" alt=""><figcaption><p>生成S3 憑證Key</p></figcaption></figure>

<figure><img src="https://1934262382-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRmnDr9RXeSmhkUmaUsX7%2Fuploads%2FPkhg45mPh1wyDokFCpvY%2F%E6%88%AA%E5%9C%96%202022-12-23%20%E4%B8%8B%E5%8D%883.14.15.png?alt=media&#x26;token=6d192920-f1e2-4f0b-ac3b-f141a3cdf3a1" alt=""><figcaption><p>再自行複製下來</p></figcaption></figure>

<figure><img src="https://1934262382-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRmnDr9RXeSmhkUmaUsX7%2Fuploads%2FVy8ueILv4VdPhfqHz6OZ%2F%E6%88%AA%E5%9C%96%202022-12-23%20%E4%B8%8B%E5%8D%883.23.16.png?alt=media&#x26;token=9fdbcb46-f9c7-4710-a9be-0f3f3a9f7461" 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();
	}
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xu-min-chang.gitbook.io/caster-develop-note/java/cloud-platform/ovhcloud/config.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
