Secure Files - AWS

Secure File Storage App for Agility CMS using AWS S3

Description: This app enables you to securely store and manage files in Agility CMS using AWS S3. By integrating AWS S3, you can leverage its robust security features and scalability to handle your file storage needs efficiently.

Setup Instructions:

  1. Create an AWS S3 Bucket:
  2. Retrieve Access Keys:

Configuration in Agility CMS:

  1. In Agility CMS, navigate to the App section in settings and add the Secure Files - AWS app.
  2. Enter the connection string and access key values obtained from Azure Blob Storage in the Azure Portal.
  3. Save the configuration to enable the app.
  4. Add the Secure File custom field to a Content or Component Model.

Code Example:

To deliver files to the frontend using a pre-signed URL, you can use the following code snippet:

//use env vars for the bucket and credentials, or authenticate another way
const bucketName = process.env.AWS_S3_BUCKET_NAME || ""
const region = process.env.AWS_S3_REGION || ""
const accessKeyId = process.env.AWS_S3_ACCESS_ID || ""
const secretAccessKey = process.env.AWS_S3_SECRET_KEY || ''

const s3Config: S3ClientConfig = {
	credentials: {
    	accessKeyId,
		secretAccessKey,
	},
	region,
};
//pull the filename from your agility content item value
const s3Client = new S3Client(s3Config);
const command = new GetObjectCommand({ Bucket: bucketName, Key: filename });
const signedUrlRes = await getSignedUrl(s3Client, command, { expiresIn: 10 });

//redirect to the signed URL
return Response.redirect(signedUrlRes, 302)

This code generates a pre-signed URL that allows secure access to a specific object in your S3 bucket for a limited time. You can use this URL in your frontend to enable users to download files securely.