Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@aws-sdk/s3-request-presigner
Advanced tools
[![NPM version](https://img.shields.io/npm/v/@aws-sdk/s3-request-presigner/preview.svg)](https://www.npmjs.com/package/@aws-sdk/s3-request-presigner) [![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/s3-request-presigner/preview.svg)](https://www.n
The @aws-sdk/s3-request-presigner package is part of the AWS SDK for JavaScript (v3) and is used to generate pre-signed URLs for AWS S3 objects. This allows clients to perform operations on S3 objects, such as GET or PUT, without requiring AWS credentials, by providing a URL that includes a signature. This is useful for providing temporary access to private objects, uploading files directly from a browser, or any other operation that you want to allow without giving out AWS credentials.
Generate pre-signed GET URL
This feature allows you to create a pre-signed URL for a GET request on an S3 object. The URL will be valid for the duration specified by 'expiresIn' (in seconds).
const { S3Client, GetObjectCommand } = require('@aws-sdk/client-s3');
const { getSignedUrl } = require('@aws-sdk/s3-request-presigner');
const s3Client = new S3Client({ region: 'us-west-2' });
const getObjectParams = { Bucket: 'my-bucket', Key: 'my-object-key' };
const command = new GetObjectCommand(getObjectParams);
const signedUrl = await getSignedUrl(s3Client, command, { expiresIn: 3600 });
console.log('The signed URL is:', signedUrl);
Generate pre-signed PUT URL
This feature allows you to create a pre-signed URL for a PUT request to upload an object to S3. The URL will be valid for the duration specified by 'expiresIn' (in seconds).
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3');
const { getSignedUrl } = require('@aws-sdk/s3-request-presigner');
const s3Client = new S3Client({ region: 'us-west-2' });
const putObjectParams = { Bucket: 'my-bucket', Key: 'my-object-key' };
const command = new PutObjectCommand(putObjectParams);
const signedUrl = await getSignedUrl(s3Client, command, { expiresIn: 3600 });
console.log('The signed URL is:', signedUrl);
The 'aws-sdk' package is the previous version of the AWS SDK for JavaScript. It also supports generating pre-signed URLs for S3 objects, but it is not modular like the newer '@aws-sdk/s3-request-presigner' and includes the entire AWS SDK.
This package provides a presigner based on signature V4 that will attempt to generate signed url for S3.
JavaScript Example:
const S3Presigner = require("@aws-sdk/s3-request-presigner").S3RequestPresigner;
const browserSha256 = require("@aws-crypto/sha256-browser").Sha256;
const nodeSha256 = require("@aws-sdk/hash-node").Hash;
const signer = new S3Presigner({
region: regionProvider,
credentials: credentialsProvider,
sha256: nodeSha256 //if the signer is used in browser, use `browserSha256` then
});
const Day = 24 * 60 * 60 * 1000;
const expiration = new Date(Date.now() + 1 * Day);
const url = signer.presignRequest(request, expiration);
Typescript Example:
import { S3RequestPresigner } from "@aws-sdk/s3-request-presigner";
import { Sha256 as browserSha256 } from "@aws-crypto/sha256-browser";
import { Hash as nodeSha256 } from "@aws-sdk/hash-node";
const signer = new S3RequestPresigner({
region: regionProvider,
credentials: credentialsProvider,
sha256: nodeSha256 //if the signer is used in browser, use `browserSha256` then
});
const Day = 24 * 60 * 60 * 1000;
const expiration = new Date(Date.now() + 1 * Day);
const url = signer.presignRequest(request, expiration);
To avoid redundant construction parameters when instantiate the s3 presigner, you can simply spread the configurations of an existing s3 clients and supply to the presigner's constructor.
//s3 is instantiated from S3Client from @aws-sdk/client-s3-* packages
const signer = new S3RequestPresigner({
...s3.config
});
FAQs
[![NPM version](https://img.shields.io/npm/v/@aws-sdk/s3-request-presigner/latest.svg)](https://www.npmjs.com/package/@aws-sdk/s3-request-presigner) [![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/s3-request-presigner.svg)](https://www.npmjs.com/
The npm package @aws-sdk/s3-request-presigner receives a total of 2,270,973 weekly downloads. As such, @aws-sdk/s3-request-presigner popularity was classified as popular.
We found that @aws-sdk/s3-request-presigner demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.