Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
feat: add option "expiration" to extend signed requests (#248)
Browse files Browse the repository at this point in the history
* HTTPError: Response code 403 (Forbidden) #237

* HTTPError: Response code 403 (Forbidden) #237
  • Loading branch information
Vacilando authored Nov 24, 2020
1 parent 8f52af0 commit 2ffb33a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ module.exports = {
region: process.env.AWS_REGION,
},
buckets: ["my-bucket", "my-second-bucket"],
expiration: 120,
},
},
],
};
```

The value of expiration specifies the time after which signed requests to S3 will expire. The default value is 60 seconds. Feel free to increase if you have many or large images and start to see errors similar to "HTTPError: Response code 403 (Forbidden)" during build. This option is not compulsory.

### AWS setup

You can use the plugin both with private and public buckets.
Expand Down
5 changes: 3 additions & 2 deletions src/gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type pluginOptionsType = {
region: string;
};
buckets: string[];
expiration: number;
};

type ObjectType = AWS.S3.Object & { Bucket: string };
Expand All @@ -20,7 +21,7 @@ export async function sourceNodes(
{ actions: { createNode }, createNodeId, createContentDigest, reporter },
pluginOptions: pluginOptionsType
) {
const { aws: awsConfig, buckets } = pluginOptions;
const { aws: awsConfig, buckets, expiration = 60 } = pluginOptions;

// configure aws
AWS.config.update(awsConfig);
Expand Down Expand Up @@ -91,7 +92,7 @@ export async function sourceNodes(
const url = s3.getSignedUrl("getObject", {
Bucket,
Key,
Expires: 60,
Expires: expiration,
});

createNode({
Expand Down

0 comments on commit 2ffb33a

Please sign in to comment.