[英]Is it safe to cache AmazonS3 client for later use?
I am writing a Java program to upload files to AWS S3 and I have succeed to get the S3 client using the following code:我正在编写一个 Java 程序来将文件上传到 AWS S3,并且使用以下代码成功获取了 S3 客户端:
BasicAWSCredentials awsCreds = new BasicAWSCredentials("aaa", "bbb");
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withRegion(Regions.fromName("ccc"))
.withCredentials(new AWSStaticCredentialsProvider(awsCreds)).build();
As I find that it takes quite a few seconds each time to setup the S3 client, I am wondering if it is possible to cache the client for repeated use.由于我发现每次设置 S3 客户端都需要花费几秒钟的时间,我想知道是否可以缓存客户端以供重复使用。
Also, if I cache the client for like a year, will the client still be valid to connect to AWS?另外,如果我将客户端缓存一年左右,客户端是否仍然可以有效连接到 AWS?
Your client will work as long as the the credentials are valid.只要凭据有效,您的客户端就会工作。 It will work for a year if your credentials are not changed or updated.
如果您的凭据没有更改或更新,它将工作一年。
Basically, when you create a client, you don't convert the original credentials to any form, everything will be reference later when needed to perform the actual operation.基本上,当您创建客户端时,您不会将原始凭据转换为任何形式,所有内容都将在稍后需要执行实际操作时参考。
Your client will no longer work once you update your credentials after its object creation.一旦您在创建对象后更新凭据,您的客户端将不再工作。
If you want to initialize once and use it later for a year.如果您想初始化一次并在一年后使用它。 Yes, it will work .
是的,它会起作用。 With the best security practices , it is not good to keep the credentials fixed for a longer period of time.
使用最佳安全实践,将凭据固定较长时间是不好的。
More about credentials:有关凭据的更多信息:
https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/credentials.html https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/credentials.html
Hope it helps.希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.