-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
S3 PutObject default "Cache-Control" value is set to "no-cache" #2603
Comments
Hello @ShimYama , Thank you very much for your submission. I am not sure I have understood your submission properly. If you mean that there is no Control Cache header when not using
There is no cache-control header by default for PutObjectRequest : If you take a look at the PutObjectRequest implementation: if(m_cacheControlHasBeenSet)
{
ss << m_cacheControl;
headers.emplace("cache-control", ss.str());
ss.str("");
}
I am not sure with version of AWS CLI you are using however the behavior is as follow:
See AWS CLI V2 documentation.
See documentation. For reference, you can read more about the cache control header here : https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html Now if you mean that there is a control-cache header present with value set as "no-cache" when not using If this is your experience, I would recommend to check through the console if you have set any metadata set for Cache-Control in the affected folder. (You can refer to the Behavior for the AWS Console above). Let me know if you have any questions or need further informations. Best regards, Yasmine |
This is what I have experienced.
I created a new bucket with default settings and uploaded files from sdk but this issue happened, so I don't think I've added a cache-control behavior settings to my bucket or folder... I also check My AWS CLI version |
Hello @ShimYama , This is a very odd behavior. Especially if you have that Aws::S3::Model::PutObjectRequest my_request;
my_request.SetCacheControl("no-cache"); Have you checked through the console if you have set any metadata set for Cache-Control as mentioned above? Thank you very much for your time and collaboration. Sincerely, Yasmine |
I created bucket via AWS console (i.e. on web browser) with default settings; I just set a name and a region of a bucket. I can reproduce this issue with the sdk sample code below. I added some lines for logging but the core process is not modded. #ifndef TESTING_BUILD
+#include "aws/core/utils/logging/LogLevel.h"
int main() {
+ _putenv_s("AWS_EC2_METADATA_DISABLED", "true");
+
Aws::SDKOptions options;
+ options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace;
Aws::InitAPI(options);
{
//TODO(user): Change bucket_name to the name of a bucket in your account.
- const Aws::String bucket_name = "<Enter bucket name>";
+ const Aws::String bucket_name = "<--MyBucketName-->";
//TODO(user): Create a file called "my-file.txt" in the local folder where your executables are built to.
- const Aws::String object_name = "<Enter file>";
+ const Aws::String object_name = "sample.txt";
Aws::Client::ClientConfiguration clientConfig;
// Optional: Set to the AWS Region in which the bucket was created (overrides config file).
- // clientConfig.region = "us-east-1";
+ clientConfig.region = "ap-northeast-1";
AwsDoc::S3::PutObject(bucket_name, object_name, clientConfig);
}
Aws::ShutdownAPI(options);
return 0;
}
#endif // TESTING_BUILD And this is a log file. I hope this helps you to find what is wrong. |
Hello @ShimYama , Apologies but the log you have provided the header contains no cache-control header. It seems that the SDK is behaving as expected here and is not setting any "Cache-Control" in the metadata section. The behavior with the sample is as follow:
Aws::S3::Model::PutObjectRequest my_request;
my_request.SetCacheControl("no-cache"); The request contains the following header :
Aws::S3::Model::PutObjectRequest my_request;
//my_request.SetCacheControl("no-cache"); (That is not: using SetCacheControl) The request does not contain the
I am not sure why you are seeing metadata associated with your object under the properties metadata tab of the object if you are creating a bucket. Are you doing any other modification/steps besides the one listed above? I apologies for the redundancy but the question asked in my previous two comments is still unanswered: Best regards, Yasmine |
Thank you for your answer. I didn't add any SetCacheControl settings, so I also tested this source so that I didn't add any special setting to my bucket or something. #include <aws/core/Aws.h>
#include <aws/core/utils/logging/LogLevel.h>
#include <aws/s3/S3Client.h>
#include <aws/s3/model/BucketLocationConstraint.h>
#include <aws/s3/model/CreateBucketRequest.h>
#include <aws/s3/model/GetObjectRequest.h>
#include <aws/s3/model/PutObjectRequest.h>
#include <iostream>
#include <fstream>
using namespace Aws;
static String bucketName = "<new bucket name>";
static String fileName = "sample.txt";
int main()
{
_putenv_s("AWS_EC2_METADATA_DISABLED", "true");
SDKOptions options;
options.loggingOptions.logLevel = Utils::Logging::LogLevel::Trace;
InitAPI(options);
{
S3::S3ClientConfiguration clientConfig;
clientConfig.scheme = Http::Scheme::HTTPS;
clientConfig.region = Region::AP_NORTHEAST_1;
S3::S3Client client(clientConfig);
{
S3::Model::CreateBucketRequest request;
request.SetBucket(bucketName);
S3::Model::CreateBucketConfiguration createBucketConfig;
createBucketConfig.SetLocationConstraint(S3::Model::BucketLocationConstraintMapper::GetBucketLocationConstraintForName(clientConfig.region));
request.SetCreateBucketConfiguration(createBucketConfig);
auto outcome = client.CreateBucket(request);
if (outcome.IsSuccess()) {
std::cout << "Created bucket " << bucketName << " in the specified AWS Region." << std::endl;
}
}
{
S3::Model::PutObjectRequest request;
request.SetBucket(bucketName);
request.SetKey(fileName);
std::shared_ptr<IOStream> inputData = std::make_shared<FStream>(fileName.c_str(), std::ios_base::in | std::ios_base::binary);
request.SetBody(inputData);
std::cout << "Cache Control has been set: " << (request.CacheControlHasBeenSet() ? "Yes" : "No") << std::endl;
std::cout << "Cache Control value: " << request.GetCacheControl() << std::endl;
auto outcome = client.PutObject(request);
if (outcome.IsSuccess()) {
std::cout << "Added object '" << fileName << "' to bucket '" << bucketName << "'." << std::endl;
}
}
{
S3::Model::GetObjectRequest request;
request.SetBucket(bucketName);
request.SetKey(fileName);
auto outcome = client.GetObject(request);
if (outcome.IsSuccess()) {
std::cout << "Cache Control: " << outcome.GetResult().GetCacheControl() << std::endl;
}
}
}
ShutdownAPI(options);
return 0;
} And I got this result and a log.
It seems my file was uploaded without cache control settings but for some reason s3 adds cache-control settings automatically. |
Hello @ShimYama , I have attempted this exact code sample and the file is still uploaded without cache control settings. I will reach out to s3 to see if they have any guidance to provide on why this behavior is happening, however it seems like this is not an SDK issue. Thank you very much for providing all the requested information. Best regards, Yasmine |
Hi Yasmine, Did the s3 team have any insight? This bug is causing us a great deal of trouble as well. Regards, |
Hello @gbrownewell , I unfortunately haven't gotten a response from the S3 team yet. I will raise this again and provide an update here as soon as I hear back from them. Best regards, Yasmine |
Fixed with this: #2998 |
This issue is now closed. Comments on closed issues are hard for our team to see. |
Describe the bug
When I upload files to Amazon S3 with sdk, their "Cache-Control" in metadata section is always set to "no-cache" even if I didn't set it.
I also uploaded files with Amazon CLI and their metadata don't have any "Cache-Control" keys.
I also tested sample program in aws-doc-sdk-examples repository and the same problem occurs.
Expected Behavior
Don't set anything if cache control is not set.
Current Behavior
S3::Model::PutObjectRequest::SetCacheControl()
is not usedS3::Model::PutObjectRequest::SetCacheControl()
is used (for example,SetCacheControl("max-age=1000");
)Reproduction Steps
Just upload files using
S3::S3Client::PutObject()
method without usingS3::Model::PutObjectRequest::SetCacheControl()
.You can reproduce it with sample source.
Possible Solution
No response
Additional Information/Context
No response
AWS CPP SDK version used
1.11.127
Compiler and Version used
Visual Studio 2015 Community / Build Engine version 14.0.25420.1
Operating System and version
Windows 10 Pro 22H2
The text was updated successfully, but these errors were encountered: