قالب وردپرس درنا توس
Home / Tips and Tricks / How to use DigitalOcean spaces for storage of alternative object S3 – CloudSavvy IT

How to use DigitalOcean spaces for storage of alternative object S3 – CloudSavvy IT



Digital Ocean logo

DigitalOcean Spaces offers Amazon S3-compatible object storage for a low cost and with a built-in CDN. Especially if you use the DigitalOcean services, Spaces offers a great way to store backup files (when used as a private archive) or even host a static website using CDN capabilities.

  • $ 5 per month
  • 250 GB storage space
  • 1
    TB outgoing transfer
  • Unlimited uploads
  • Creation of an unlimited number of spaces

In this article, we will explore how to get started with DigitalOcean Spaces and some common operations that would be used.

Create a space

Once you have logged in to DigitalOcean and chosen to create a new space, you will be presented with the options for providing your space. You must decide the following:

  • Datacenter Region
  • If you want to enable CDN or not
  • Allow or restrict the file list
  • Decide a name for the space

The file list does not determine whether or not an anonymous user can view a file, only if they could list the name, size, and additional metadata of files stored in space.

In this example, we choose to create the space in Datacenter Region 2, San Francisco, enable CDN (without a custom subdomain), and restrict the anonymous file list.

Finally, we will choose a unique name, lc-articles in this case and whether it should be placed in a project. Next we will click on Create a space button to provide our space.

Outside the newly created space you will see that there are no files but through the interface we can easily upload files or create folders if needed.

Clicking Settings shows all the configurations we can change. Several additional features here are very useful. In particular the option Purge Cache and CORS configurations.

Create access keys for spaces

Navigate to the Account → API section and under the Tokens section you will find the Generate new key for space access keys.

Enter a name to identify the access key. Once you have saved, you will be presented with the key and associated secret.

Make sure to copy the secret value out, once this is hidden, by navigating away from the page or performing another operation you will not be able to get back to the secret value.

We will use these two values ​​to connect to the DigitalOcean Space we created.

Configure S3Cmd

In this article, we will use the popular S3Cmd tool to upload files from an Ubuntu server. After installing S3Cmd, which can be done in Ubuntu with apt install s3cmd, we need to create a configuration file. The easiest way to get started is to use s3cmd --configure command. There are a number of different settings that we need to configure.

  • access key – The same access key that was created on the API tox page.
  • Secret key – The same secret key that was created on the API tox page.
  • standard Regions – Left by default US in this example.
  • S3 Endpoint – This is the same end point as shown on the space settings page.
  • DNS-based bucket syntax – Instead of the default value, this should reflect the correct endpoint: %(bucket)s.{region}.digitaloceanspaces.com. Replace {region} with the correct value displayed on the settings page.
  • encryption Password – Leave blank in this example.
  • GPG program path Left to use the default path for GPG applications.
  • HTTPS protocol – Left to use the default to use the HTTPS protocol.
  • Agent – Left by default for no proxy connection.

It is also wise to use the test connection option to make sure the settings are correct before saving the configuration file.

We can verify that this works by just running the command s3cmd ls. If we see output from our newly created Space (bucket in S3 parlance), we know that the connection works.

Upload files

The first operation we will show is to upload files or files to our space. The command to upload a file is very simple:

s3cmd put filename s3://DigitalOcean-Space-Name

As you can see from the screenshot above, the file has been successfully uploaded. In addition, you can also verify this in the GUI.

List files

How can we list what files are currently available in space? Much like the regular Linux command ls, we use a similar one with S3Cmd.

s3cmd ls s3://DigitalOcean-Space-Name

To retrieve additional information about a given file in Space., We can use info command to list metadata associated with the object.

s3cmd info s3://DigitalOcean-Space-Name/filename

Delete files

Deleting files is as easy as previous operations. Now that we have uploaded our file and been able to list that file, we can use the path to allow us to delete the file.

s3cmd del s3://DigitalOcean-Space-Name/filename

As you can see, we have removed [testfile1.zip]() and verified via the command line that the file is no longer listed in space. Also, if we check the GUI, we can see that the file has also been shown as deleted.

Conclusion

DigitalOcean Spaces offers a compelling mix of low-cost features to suit many of the needs of a system administrator looking to leverage a low-cost storage space. Because DigitalOcean is generally focused on rapid development and robust production services, it is a convenient and frequently used ability to quickly store large files, available for multiple servers.

One of the most popular uses is to store system backups here. If you use a traditional backup method, such as creating a TAR or ZIP file, you can easily transfer these files in a script to a DigitalOcean Space. Check out how fast and easy it is to get started on the DigitalOcean website!


Source link