Im implementing Varnish HTTP proxy to serve content from S3 bucket. The content is very big JS client 2K+ files. I found out this guide https://info.varnish-software.com/blog/using-varnish-cache-secured-aws-s3-gateway
In general it signs http requests and redirects them to s3 endpoint
sub vcl_backend_fetch
{
set bereq.http.Host = "bucket.s3.amazonaws.com";
set bereq.http.Date = now;
set bereq.http.NL = {"
"};
set bereq.http.Authorization = "AWS YOURVERYLONGACCESSID:" +
digest.base64_hex(digest.hmac_sha1("somelongvalueforsecret",
bereq.method + bereq.http.NL + bereq.http.Content-MD5 + bereq.http.NL +
bereq.http.Content-Type + bereq.http.NL + bereq.http.Date + bereq.http.NL +
"/" + "bucket" + bereq.url
));
unset bereq.http.NL;
}
It work for retrieving files, however if i have http parameters in url i want to fetch it fails with error SignatureDoesNotMatch
.
The code that i was using was outdated. I needed to sign my requests with sig4 version of AWS REST API. This repo was helpful:
https://github.com/xcir/libvmod-awsrest
IMPORTANT: be carefull if you url contain special symbols @ & [] etc. In my case signature was failing because i had [ and ] symbols in name of the files. Ive replaced them
and it worked.