Learning objectives
After reading this article you will be able to:
- Read the error code and tell a signature problem from a permission problem
- Diagnose keys, endpoint, region and clock with the aws-cli
- Fix the addressing style, the bucket policy and expired presigned URLs
You copied the keys, configured the SDK, ran the upload and got a 403. The message is short, the status is the same for half a dozen different problems, and the code works on your teammate's machine. Changing things at random usually makes it worse, because every attempt moves two variables at once.
The fastest route is to read the error code, which already separates the families of causes, and to test one hypothesis at a time with the aws-cli. This guide applies to Amazon S3 and to any S3-compatible storage, since they all use the same signature scheme (SigV4) and almost always the same codes.
What does the error look like?#
At the API level, the storage answers with XML. The field that matters is Code:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
<RequestId>4442587FB7D0A2F9</RequestId>
</Error>In the aws-cli and the SDKs, the same code shows up in parentheses:
An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
An error occurred (InvalidAccessKeyId) when calling the ListObjectsV2 operation: The AWS Access Key Id you provided does not exist in our records.
An error occurred (RequestTimeTooSkewed) when calling the PutObject operation: The difference between the request time and the current time is too large.
An error occurred (403) when calling the HeadObject operation: ForbiddenThe last line deserves attention. aws s3 cp sends a HEAD before downloading, and a HEAD response has no body, so you only see the status, not the code. To find out which 403 it is, repeat the operation with --debug or GET the same object.
The message text varies a little between providers. The code is what counts:
| Code | Status | What it means | Check first |
|---|---|---|---|
InvalidAccessKeyId |
403 | The access key does not exist on that storage | Configured endpoint, access key with no stray spaces |
SignatureDoesNotMatch |
403 | The signature the storage computed does not match yours | Secret, region and signed headers |
RequestTimeTooSkewed |
403 | The request time is too far from the server's time | The machine's clock and NTP |
AccessDenied |
403 | No permission for the action, or an expired presigned URL | Key permissions and URL lifetime |
AuthorizationHeaderMalformed |
400 | The authorization header is invalid | Region in the signature's scope |
PermanentRedirect |
301 | The bucket must be reached through another endpoint | The endpoint for the bucket's region |
NoSuchBucket |
404 | That bucket does not exist on that endpoint | Bucket name and addressing style |
The first three are authentication problems: the storage never got to decide whether you may do it. AccessDenied is usually authorization: it knows who you are and says no.
What are the causes, from most to least common?#
- Wrong key. A pasted space or newline, access key and secret swapped, keys from another account or another provider. An unknown access key returns
InvalidAccessKeyId; a wrong secret returnsSignatureDoesNotMatch. A sneaky case is a forgotten environment variable. In the aws-cli,AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_SESSION_TOKENandAWS_PROFILEoverride whatever is in the config file. - Wrong endpoint or region. Without a configured endpoint, the SDK talks to AWS itself, where your provider's key does not exist, and the answer is
InvalidAccessKeyId. The region is part of the signature's credential scope (date/region/s3/aws4_request): if it is not the one the storage expects, validation fails. On AWS, reaching a bucket through another region's endpoint returnsPermanentRedirect(301). - Skewed clock. On Amazon S3, the signed part of a request is valid for 15 minutes around the timestamp it carries. A VM back from suspend, a container on a host without NTP or a laptop with the wrong time goes past that and gets
RequestTimeTooSkewed. - Path-style or virtual-hosted. In virtual-hosted style the bucket goes in the hostname (
https://my-bucket.s3.us-west-2.amazonaws.com/photo.jpg); in path-style it goes in the path (https://s3.us-west-2.amazonaws.com/my-bucket/photo.jpg). Host and path are part of what gets signed. Some S3-compatible services only accept path-style, and a client that builds the other format gets, depending on the provider, a DNS error, aNoSuchBucketor a signature rejection. - Bucket policy or key permissions. The key is valid but lacks the action (
s3:PutObject,s3:GetObject,s3:ListBucket), a policy explicitly denies it, or the request arrived unsigned at a private bucket. On Amazon S3, a caller withouts3:ListBucketgets 403, not 404, for an object that does not exist. - Expired or altered presigned URL. After the deadline, the answer is
AccessDeniedwith the messageRequest has expired. The URL also dies early when the credential that signed it expires or is deactivated. Using a URL generated for GET with PUT, or sending a header different from the one that was signed, returnsSignatureDoesNotMatch.
How do you diagnose it with the aws-cli?#
The aws-cli is a known client that signs correctly (how it compares with rclone, s3cmd and the SDKs is in the best S3 client tools). If it works with the same keys, the problem is in your code; if it fails, it is in the keys, the endpoint or the permissions. Test in this order:
# 1. Which credentials and region are in use, and where they came from
aws configure list
env | grep '^AWS_'
# 2. A simple listing, with explicit endpoint and region
aws s3 ls s3://my-bucket --endpoint-url "$S3_ENDPOINT" --region "$S3_REGION"
# 3. If it fails, the canonical request that was signed (compare it with your code's)
aws s3 ls s3://my-bucket --endpoint-url "$S3_ENDPOINT" --region "$S3_REGION" \
--debug 2>&1 | grep -A 12 'CanonicalRequest'
# 4. Path-style, if the provider requires it
aws configure set default.s3.addressing_style pathaws configure list shows each item's value, where it came from (config file, environment variable) and the variable's name. That is where the AWS_PROFILE you set months ago shows up. On Amazon S3, the XML of a SignatureDoesNotMatch carries the StringToSign and CanonicalRequest fields, what the service signed on its side; compare them with the --debug output to see which part differs.
For the clock, compare your machine's time with the storage's Date header:
date -u
curl -sI "$S3_ENDPOINT" | grep -i '^date:'
timedatectl status # look for "System clock synchronized: yes"For a presigned URL, generate a fresh one with the aws-cli and test it with curl. If the aws-cli URL works and yours does not, the difference is in how you generate it:
URL=$(aws s3 presign s3://my-bucket/test.txt --expires-in 300 \
--endpoint-url "$S3_ENDPOINT" --region "$S3_REGION")
curl -i "$URL"How do you fix each cause?#
Nearly every key, endpoint, region and addressing error goes away once the client configuration is explicit and comes from environment variables. Example with the AWS SDK v3 for JavaScript (npm install @aws-sdk/client-s3), saved as check-s3.mjs:
import { ListObjectsV2Command, S3Client } from "@aws-sdk/client-s3";
const s3 = new S3Client({
endpoint: process.env.S3_ENDPOINT, // without it, the SDK talks to AWS
region: process.env.S3_REGION, // the region your provider documents
forcePathStyle: process.env.S3_PATH_STYLE === "true",
credentials: {
accessKeyId: process.env.S3_ACCESS_KEY.trim(), // strips spaces and newlines
secretAccessKey: process.env.S3_SECRET_KEY.trim(),
},
});
try {
const out = await s3.send(
new ListObjectsV2Command({ Bucket: process.env.S3_BUCKET, MaxKeys: 5 }),
);
console.log("ok, objects listed:", out.KeyCount);
} catch (err) {
// err.name is the storage's code: AccessDenied, SignatureDoesNotMatch...
console.log(err.name, err.$metadata?.httpStatusCode, err.message);
}In boto3, the equivalents are endpoint_url, region_name and Config(signature_version="s3v4", s3={"addressing_style": "path"}). Environment variables prevent the silliest mistake of all: the right key on your laptop and the old one on the server.
If the error started after you updated the SDK or the aws-cli, look at checksums. The AWS SDKs switched to calculating a CRC checksum on every upload by default (in the AWS SDK v3 for JavaScript, from 3.729.0 on), and some S3-compatible services reject that header. To test, set AWS_REQUEST_CHECKSUM_CALCULATION=WHEN_REQUIRED or pass requestChecksumCalculation: "WHEN_REQUIRED" to the S3Client.
For the other causes:
- Clock: turn on time sync (
sudo timedatectl set-ntp trueon Linux,w32tm /resyncon Windows). Containers use the host's clock, so fix the host. - Permissions: check the bucket policy (
aws s3api get-bucket-policy --bucket my-bucketon Amazon S3) and the actions granted to the key. On AWS, anAccessDeniedmessage within the same account or organization names the policy type that denied it, such aswith an explicit deny in a resource-based policy. To decide what should be public, see public vs private files. - Presigned URL: generate the URL when the user asks for it, with a short lifetime, and never store it in the database. Sign the method and headers the client will send. The mechanics are in what is a presigned URL. If the error only shows up in the browser, the problem may be CORS on direct uploads.
How do you keep it from coming back?#
- One set of keys per environment, always in environment variables, never in code.
- A smoke test at app startup or in CI: a
ListObjectsV2withMaxKeys: 1fails early, with the right code, instead of failing on a user's first upload. - Log the error code and the
RequestId, not just the status. "403" alone tells you nothing. - Give the key the least privilege it needs, but test every action the code uses: granting
PutObjectand forgettingListBucketis common. - NTP on every machine that signs requests.
If you are still picking tools, what is S3-compatible storage explains why the same SDK works across providers, and what is a bucket covers the name that goes into every request.
How to do this on Square Cloud#
On Square Cloud Blob Storage, the checklist above comes down to a few values. S3 keys are derived from an API key and live in the "S3 access" tab of the dashboard. The endpoint is https://s3-blob.squarecloud.app and the region is auto; in the example above, also set S3_PATH_STYLE=true, so the bucket goes in the URL path.
Buckets are fixed: public and private, plus legacy, which is read-only. You cannot create buckets with other names, and folders are key prefixes: the Bucket parameter takes one of those names, and the folder goes in the Key.
If a write is refused, check the two conditions for a PUT through a presigned URL: the API key needs write permission and the plan has to be active. An upload that would go past the plan's storage quota is also refused while the optional overage is off. SigV4 presigned URLs last up to 7 days, and the same files are available through the REST API and the dashboard if you would rather skip SigV4. See the details on the Blob Storage page.
Blob Storage
S3-compatible object storage with no egress fees
FAQs
What is the difference between AccessDenied and SignatureDoesNotMatch?
SignatureDoesNotMatch means the storage recalculated the signature and it did not match: a wrong secret, a different region or something in the request that changed after signing. AccessDenied usually means the request arrived but the identity has no permission for that action; an expired presigned URL also returns AccessDenied.
Why do I get 403 instead of 404 for an object that does not exist?
On Amazon S3, a caller without the s3:ListBucket permission on the bucket gets 403 Access Denied when asking for a missing object, so the response does not reveal what exists. With that permission, the answer is 404 Not Found.
How far off can the clock be before RequestTimeTooSkewed?
On Amazon S3, the signed part of a request is valid within 15 minutes of the timestamp it carries. Other S3-compatible services may use a different window. Sync the machine with NTP instead of setting the time by hand.
Can I use the aws-cli with storage that is not AWS?
Yes. Pass --endpoint-url (or set AWS_ENDPOINT_URL), use the region your provider documents and the keys it issued. If the provider requires path-style, run aws configure set default.s3.addressing_style path.
More in Storage
See all 24 articles- What is a presigned (signed) URL?A presigned URL is a temporary link to a private file that works without login or credentials. See how it works, its limits and when to use it.
- What is object storage?Object storage keeps files as objects with a key and metadata, accessed over an HTTP API. See how it works, what it is for and where its limits are.
- What does 'S3-compatible' storage mean?S3 is Amazon's object storage and its API became the industry standard. Learn what S3-compatible means, what differs between providers, and how to connect.
- Uploading large files: multipart and resumable uploadsMultipart upload splits a large file into parts that are sent in parallel and retried on their own. See the Python walkthrough, how to resume, and common mistakes.