Search code examples
amazon-web-servicesamazon-s3pre-signed-url

AWS Pre-Signed Post URL suddenly stopped working


So I have been working with aws-s3 post signed URLs for a month now and it was working as a charm all of sudden( I didn't change any policies for my IAM user or bucket) it start giving me forbidden request.

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>AccessDenied</Code>
    <Message>Invalid according to Policy: Policy expired.</Message>
</Error>

I found that AWS sent me an email informing me that my trail ended does this has anything to do with it.

Note:I can still upload files to my s3 manually

Edit

The code

const params = {
    Bucket: 'ratemycourses',
    Fields: {
      key: `profileImage/${userId}/profile.jpeg`,
      acl: 'public-read',
      'Content-Type': 'multipart/form-data',
    },
    Expires: 60,
  };
  const data = await s3.createPresignedPost(params) //I made the callback function promisifed;
  return data;

Solution

  • The expiration element in your POST policy specifies the expiration date/time of the policy. It looks like your policy has expired. Correct the policy expiration, and then re-create your signed URL.

    Here's an example of a POST policy:

    {
        "expiration": "2021-07-10T12:00:00.000Z",
        "conditions": [
            {"bucket": "mybucket" },
            ["starts-with", "$key", "user/shahda/"],
        ]
    }