Skip to main content

AWS S3

Credential configuration

To configure this credential, you need the Access Key ID and the Secret Access Key of the Programatic access user you want to use. Make sure this user has the required permissions to access S3 to work properly. If you need to create the user, follow the instructions provided here.

In the extra options field, you can include any of the parameters found here.

Here is an example of a filled credential configuration form in YepCode:

AWS S3 Snippets available in YepCode editor

note

The title is the triggering text for YepCode to autocomplete the script.

Integration

New integration from credential
const awsS3Client = yepcode.integration.awsS3("credential-slug");
New integration from plain authentication data
const { S3Client } = require("@aws-sdk/client-s3");

const awsS3Client = new S3Client({
credentials: {
accessKeyId: "accessKeyId",
secretAccessKey: "secretAccessKey",
},
});

List Buckets

List buckets
const { ListBucketsCommand } = require("@aws-sdk/client-s3");

const listBucketsCommand = new ListBucketsCommand({})

const listBucketsResult = await awsS3Client.send(listBucketsCommand);
listBucketsResult.Buckets.forEach(console.log)

Create a Bucket

Create a bucket
const { CreateBucketCommand } = require("@aws-sdk/client-s3");

const createBucketCommand = new CreateBucketCommand({ Bucket: "bucket-name" });

awsS3Client.send(createBucketCommand).then(console.log).catch(console.error);

Delete a Bucket

Delete a bucket
const { DeleteBucketCommand } = require("@aws-sdk/client-s3");

const deleteBucketCommand = new DeleteBucketCommand({ Bucket: "bucket-name" });

awsS3Client.send(deleteBucketCommand).then(console.log).catch(console.error);

Get File Content

Get file content
const { GetObjectCommand } = require("@aws-sdk/client-s3");

const getObjectCommand = new GetObjectCommand({
Bucket: "bucket-name",
Key: "object-name",
});

const getObjectResult = await awsS3Client.send(getObjectCommand);

// Result.Body is a stream of object content
getObjectResult.Body.on("data", (data) => console.log(data.toString("utf8")));

Upload File

Upload file
const { PutObjectCommand } = require("@aws-sdk/client-s3");

const putObjectCommand = new PutObjectCommand({
Body: "Some string body, or stream with defined length",
Bucket: "bucket-name",
Key: "object-name",
});

awsS3Client.send(putObjectCommand).then(console.log).catch(console.error);

Upload File with Stream

Upload file with stream
const { Upload } = require("@aws-sdk/lib-storage");

const upload = new Upload({
client: awsS3Client,
params: {
Bucket: "bucket-name",
Key: "object-name",
Body: readableStream,
},
});

upload.done().then(console.log).catch(console.error);