-
Notifications
You must be signed in to change notification settings - Fork 852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should I use single instance AmazonS3Client for whole web application or per web request create new instance #1713
Comments
Hi @madhub, As a general guidance, using the Singleton instance of AmazonS3Client class is a better approach as opposed to creating instance every time, since the credentials and profile resolution are done once. Also, if you use the Hope this provides some guidance. Thanks, |
@ashishdhingra: I am using a single instance of AmazonS3Client for one of my web applications. It is noticed that if I make a concurrent request to PutObjectAsync, it throws an intermittent error. Below is the stack trace InnerException StackTrace at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error) Any input is really appreciated. Thanks. |
@ArchanaNeog Could you please share code snippet to investigate further? I'm not sure if this is an issue with the SDK since it appears to be SocketException. Also confirm of instantiating client for every request gives the same intermittent error. Also note that objects which are Disposable should be disposed properly. |
@ashishdhingra What if we have use temporary credentials ? then single instance created in the beginning won't work right ?. Our application is Asp.net Core web API which stores data to into S3 , it receives temporary S3 credentials and bucket from another service. What is the recommendation for this use case ?. Madhu |
@madhub The use of single instance versus instance per request depends on your application scenario, where single instance has added benefit of executing initialization tasks only once. In case your AmazonS3Client requests temporary credentials from another service, then using instance per request is recommended. In this case, if you decide to use single/shared instance, then extra step to refresh the credentials, if expired, is required. Hope this helps. Thanks, |
This issue has not recieved a response in 2 weeks. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled. |
One observation was if For information about the HttpClient API behavior here |
The Question
Should I use single instance AmazonS3Client for whole web application or per web request create new instance.
We are using AWS S3 SDK to upload objects inside our ASP.NET Core web application.
Environment
This is a ❓ general question
The text was updated successfully, but these errors were encountered: