Skip to content

Instantly share code, notes, and snippets.

@jasielmacedo
Created December 20, 2022 18:33
Show Gist options
  • Save jasielmacedo/5d9b386d520feb0481d496de49f85434 to your computer and use it in GitHub Desktop.
Save jasielmacedo/5d9b386d520feb0481d496de49f85434 to your computer and use it in GitHub Desktop.
Amazon AWS Signed Files with Typescript
import * as AWS from 'aws-sdk';
// Set the region in which your bucket is located
AWS.config.update({region: 'us-east-1'});
// Set the credentials for your AWS account
AWS.config.update({accessKeyId: 'ACCESS_KEY_ID', secretAccessKey: 'SECRET_ACCESS_KEY'});
// Create an instance of the S3 client
const s3 = new AWS.S3();
// Set the name of your bucket and the key of the object you want to stream
const bucketName = 'my-bucket';
const objectKey = 'my-video.mp4';
// Set the expiration time for the signed URL, in seconds
const expiration = 60 * 60; // 1 hour
// Set the content type of the object
const contentType = 'video/mp4';
// Generate a new signed URL
const signedUrl = s3.getSignedUrl('getObject', {
Bucket: bucketName,
Key: objectKey,
Expires: expiration,
ResponseContentType: contentType
});
// The signed URL can now be used to stream the object from S3
console.log(signedUrl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment