Introducing Serverless Storage for Serverless Cloud

Dec 7, 2021

We’re excited to announce the release of Serverless Storage, an incredibly powerful, completely serverless blob storage service automatically accessible from your Serverless Cloud apps. You can now store, manipulate, and serve text and binary files without worrying about provisioning or managing infrastructure.

Access to Serverless Storage is included in the runtime environment, just import the `storage` interface from our Serverless Development Kit (SDK), and you have the ability to write, read, copy, move, list, stat, and remove files. It’s also integrated with our `api` interface, making it incredibly easy to upload files to be served publicly via a CDN or privately through securely generated links.

Scalable, secure, and massively durable

Serverless Storage is backed by Amazon S3, providing a massively scalable, secure, high-availability storage solution with 99.999999999% (11 9s) of data durability. Serverless Cloud automatically provisions and configures the resources and permissions needed to securely access files from your application, letting you stay focused on your business logic, and not worrying about how or where to store your files.

Like Serverless Data, each instance of your app has its own, fully-isolated Serverless Storage container. This allows you and your team to build and test your application without interfering with shared development environments, fighting with resource contention, or compromising production data. 

We’ve also simplified the permissions model to make sure your files stay safe and secure. All files are private and inaccessible from the outside world unless you add them to a special `/public` folder. Signed links to private files can be generated programmatically via the `api` interface by using the `sendFile()` method, and public files are accessible via your app’s endpoint in the `/public` directory.

Getting started with Serverless Storage

Serverless Storage is immediately available to all your Serverless Cloud apps. All you need to do is import the `storage` interface from the Serverless Development Kit (SDK). You then have immediate access to all Serverless Storage features.

// Require the storage interface - CommonJS
const { storage } = require("@serverless/cloud");
// ES Modules
import { storage } from "@serverless/cloud";

Note that Serverless Storage operations are asynchronous and require either `async/await` or the use of `Promises` with `.then()`.

Uploading and Serving Files

Serverless Storage is integrated with the `api` interface and CDN to make uploading, saving, and serving files a snap. The following code accepts a Multipart Form Data file upload and saves it to the `/public` directory.

import { api, storage } from '@serverless/cloud'

api.upload("/upload", async (req, res) => { 
  // Write uploaded file to storage
  await storage.write(“/public/” + req.files[0].originalname, req.files[0].buffer);
  return res.send(“File saved”);

Files that aren’t in the `/public` directory will be inaccessible via the CDN, but can be served up with signed URLs using the `sendFile()` method.

import { api, storage } from '@serverless/cloud'

api.get("/protected/path", async (req, res) => {
  // Redirect to a signed URL
  return res.sendFile(“/path/to/my/privateFile.pdf”);

Other storage operations

Serverless Storage gives you the ability to read, write, and list files, as well as move, copy, and delete them. You can also use methods to check for a file’s existence and to retrieve more detailed information about a particular file. 

To learn more about Serverless Storage and its capabilities, please check out the documentation.

If you haven't tried Serverless Cloud yet, be sure to sign up!

Subscribe to our newsletter to get the latest product updates, tips, and best practices!

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.