Skip to content

Commit 9fc4db9

Browse files
committed
revamp s3 docs
1 parent 7f5dcd3 commit 9fc4db9

File tree

1 file changed

+72
-57
lines changed
  • src/content/docs/aws/services

1 file changed

+72
-57
lines changed
Lines changed: 72 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
title: "Simple Storage Service (S3)"
3-
linkTitle: "Simple Storage Service (S3)"
43
description: Get started with Amazon S3 on LocalStack
54
persistence: supported
65
tags: ["Free"]
@@ -14,30 +13,30 @@ Each object or file within S3 encompasses essential attributes such as a unique
1413
S3 can store unlimited objects, allowing you to store, retrieve, and manage your data in a highly adaptable and reliable manner.
1514

1615
LocalStack allows you to use the S3 APIs in your local environment to create new buckets, manage your S3 objects, and test your S3 configurations locally.
17-
The supported APIs are available on our [API coverage page]({{< ref "coverage_s3" >}}), which provides information on the extent of S3's integration with LocalStack.
16+
The supported APIs are available on our [API coverage page](), which provides information on the extent of S3's integration with LocalStack.
1817

1918
## Getting started
2019

2120
This guide is designed for users new to S3 and assumes basic knowledge of the AWS CLI and our [`awslocal`](https://github.com/localstack/awscli-local) wrapper script.
2221

23-
Start your LocalStack container using your [preferred method]({{< ref "getting-started/installation" >}}).
22+
Start your LocalStack container using your preferred method.
2423
We will demonstrate how you can create an S3 bucket, manage S3 objects, and generate pre-signed URLs for S3 objects.
2524

2625
### Create an S3 bucket
2726

2827
You can create an S3 bucket using the [`CreateBucket`](https://docs.aws.amazon.com/cli/latest/reference/s3api/create-bucket.html) API.
2928
Run the following command to create an S3 bucket named `sample-bucket`:
3029

31-
{{< command >}}
32-
$ awslocal s3api create-bucket --bucket sample-bucket
33-
{{< / command >}}
30+
```bash
31+
awslocal s3api create-bucket --bucket sample-bucket
32+
```
3433

3534
You can list your S3 buckets using the [`ListBuckets`](https://docs.aws.amazon.com/cli/latest/reference/s3api/list-buckets.html) API.
3635
Run the following command to list your S3 buckets:
3736

38-
{{< command >}}
39-
$ awslocal s3api list-buckets
40-
{{< / command >}}
37+
```bash
38+
awslocal s3api list-buckets
39+
```
4140

4241
On successful creation of the S3 bucket, you will see the following output:
4342

@@ -62,20 +61,20 @@ To upload a file to your S3 bucket, you can use the [`PutObject`](https://docs.a
6261
Download a random image from the internet and save it as `image.jpg`.
6362
Run the following command to upload the file to your S3 bucket:
6463

65-
{{< command >}}
66-
$ awslocal s3api put-object \
64+
```bash
65+
awslocal s3api put-object \
6766
--bucket sample-bucket \
6867
--key image.jpg \
6968
--body image.jpg
70-
{{< / command >}}
69+
```
7170

7271
You can list the objects in your S3 bucket using the [`ListObjects`](https://docs.aws.amazon.com/cli/latest/reference/s3api/list-objects.html) API.
7372
Run the following command to list the objects in your S3 bucket:
7473

75-
{{< command >}}
76-
$ awslocal s3api list-objects \
74+
```bash
75+
awslocal s3api list-objects \
7776
--bucket sample-bucket
78-
{{< / command >}}
77+
```
7978

8079
If your image has been uploaded successfully, you will see the following output:
8180

@@ -99,14 +98,17 @@ If your image has been uploaded successfully, you will see the following output:
9998

10099
Run the following command to upload a file named `index.html` to your S3 bucket:
101100

102-
{{< command >}}
101+
```bash
102+
awslocal s3api put-object --bucket sample-bucket --key index.html --body index.html
103+
```
103104

104-
$ awslocal s3api put-object --bucket sample-bucket --key index.html --body index.html
105+
The following output would be retrieved:
105106

107+
```bash
106108
{
107109
"ETag": "\"d41d8cd98f00b204e9800998ecf8427e\""
108110
}
109-
{{< / command >}}
111+
```
110112

111113
### Generate a pre-signed URL for S3 object
112114

@@ -115,9 +117,9 @@ Pre-signed URL allows anyone to retrieve the S3 object with an HTTP GET request.
115117

116118
Run the following command to generate a pre-signed URL for your S3 object:
117119

118-
{{< command >}}
119-
$ awslocal s3 presign s3://sample-bucket/image.jpg
120-
{{< / command >}}
120+
```bash
121+
awslocal s3 presign s3://sample-bucket/image.jpg
122+
```
121123

122124
You will see a generated pre-signed URL for your S3 object.
123125
You can use [curl](https://curl.se/) or [`wget`](https://www.gnu.org/software/wget/) to retrieve the S3 object using the pre-signed URL.
@@ -143,13 +145,13 @@ By default, most SDKs will try to use **Virtual-Hosted style** requests and prep
143145
However, if the endpoint is not prefixed by `s3.`, LocalStack will not be able to understand the request and it will most likely result in an error.
144146

145147
You can either change the endpoint to an S3-specific one, or configure your SDK to use **Path style** requests instead.
146-
Check out our [SDK documentation]({{< ref "sdks" >}}) to learn how you can configure AWS SDKs to access LocalStack and S3.
148+
Check out our [SDK documentation](/aws/integrations/aws-sdks) to learn how you can configure AWS SDKs to access LocalStack and S3.
147149

148-
{{< callout "tip" >}}
150+
:::note
149151
While using [AWS SDKs](https://aws.amazon.com/developer/tools/#SDKs), you would need to configure the `ForcePathStyle` parameter to `true` in the S3 client configuration to use **Path style** requests.
150152
If you want to use virtual host addressing of buckets, you can remove `ForcePathStyle` from the configuration.
151-
The `ForcePathStyle` parameter name can vary between SDK and languages, please check our [SDK documentation]({{< ref "sdks" >}})
152-
{{< /callout >}}
153+
The `ForcePathStyle` parameter name can vary between SDK and languages, please check our [SDK documentation](/aws/integrations/aws-sdks)
154+
:::
153155

154156
If your endpoint is not prefixed with `s3.`, all requests are treated as **Path style** requests.
155157
Using the `s3.localhost.localstack.cloud` endpoint URL is recommended for all requests aimed at S3.
@@ -168,12 +170,17 @@ Follow this step-by-step guide to configure CORS rules on your S3 bucket.
168170

169171
Run the following command on your terminal to create your S3 bucket:
170172

171-
{{< command >}}
172-
$ awslocal s3api create-bucket --bucket cors-bucket
173+
```bash
174+
awslocal s3api create-bucket --bucket cors-bucket
175+
```
176+
177+
The following output would be retrieved:
178+
179+
```bash
173180
{
174181
"Location": "/cors-bucket"
175182
}
176-
{{< / command >}}
183+
```
177184

178185
Next, create a JSON file with the CORS configuration.
179186
The file should have the following format:
@@ -191,22 +198,22 @@ The file should have the following format:
191198
}
192199
```
193200

194-
{{< callout >}}
201+
:::note
195202
Note that this configuration is a sample, and you can tailor it to fit your needs better, for example, restricting the **AllowedHeaders** to specific ones.
196-
{{< /callout >}}
203+
:::
197204

198205
Save the file locally with a name of your choice, for example, `cors-config.json`.
199206
Run the following command to apply the CORS configuration to your S3 bucket:
200207

201-
{{< command >}}
202-
$ awslocal s3api put-bucket-cors --bucket cors-bucket --cors-configuration file://cors-config.json
203-
{{< / command >}}
208+
```bash
209+
awslocal s3api put-bucket-cors --bucket cors-bucket --cors-configuration file://cors-config.json
210+
```
204211

205212
You can further verify that the CORS configuration was applied successfully by running the following command:
206213

207-
{{< command >}}
208-
$ awslocal s3api get-bucket-cors --bucket cors-bucket
209-
{{< / command >}}
214+
```bash
215+
awslocal s3api get-bucket-cors --bucket cors-bucket
216+
```
210217

211218
On applying the configuration successfully, you should see the same JSON configuration file you created earlier.
212219
Your S3 bucket is configured to allow cross-origin resource sharing, and if you try to send requests from your local application running on [localhost:3000](http://localhost:3000), they should be successful.
@@ -233,10 +240,10 @@ We can edit the JSON file `cors-config.json` you created earlier with the follow
233240

234241
You can now run the same steps as before to update the CORS configuration and verify if it is applied correctly:
235242

236-
{{< command >}}
237-
$ awslocal s3api put-bucket-cors --bucket cors-bucket --cors-configuration file://cors-config.json
238-
$ awslocal s3api get-bucket-cors --bucket cors-bucket
239-
{{< / command >}}
243+
```bash
244+
awslocal s3api put-bucket-cors --bucket cors-bucket --cors-configuration file://cors-config.json
245+
awslocal s3api get-bucket-cors --bucket cors-bucket
246+
```
240247

241248
You can try again to upload files in your bucket from the [LocalStack Web Application](https://app.localstack.cloud) and it should work.
242249

@@ -245,17 +252,22 @@ You can try again to upload files in your bucket from the [LocalStack Web Applic
245252
LocalStack provides a Docker image for S3, which you can use to run S3 in a Docker container.
246253
The image is available on [Docker Hub](https://hub.docker.com/r/localstack/localstack) and can be pulled using the following command:
247254

248-
{{< command >}}
249-
$ docker pull localstack/localstack:s3-latest
250-
{{< / command >}}
255+
```bash
256+
docker pull localstack/localstack:s3-latest
257+
```
251258

252259
The S3 Docker image only supports the S3 APIs and does not include other services like Lambda, DynamoDB, etc. You can run the S3 Docker image using any of the following commands:
253260

254-
{{< tabpane lang="shell" >}}
255-
{{< tab header="LocalStack CLI" lang="shell" >}}
261+
import { Tabs, TabItem } from '@astrojs/starlight/components';
262+
263+
<Tabs>
264+
<TabItem label="LocalStack CLI">
265+
```bash
256266
IMAGE_NAME=localstack/localstack:s3-latest localstack start
257-
{{< /tab >}}
258-
{{< tab header="Docker Compose" lang="yml" >}}
267+
```
268+
</TabItem>
269+
<TabItem label="Docker Compose">
270+
```yaml
259271
services:
260272
localstack:
261273
container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-main}"
@@ -267,22 +279,25 @@ services:
267279
volumes:
268280
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
269281
- "/var/run/docker.sock:/var/run/docker.sock"
270-
{{< /tab >}}
271-
{{< tab header="Docker" lang="shell" >}}
282+
```
283+
</TabItem>
284+
<TabItem label="Docker">
285+
```bash
272286
docker run \
273287
--rm \
274288
-p 4566:4566 \
275289
localstack/localstack:s3-latest
276-
{{< /tab >}}
277-
{{< /tabpane >}}
290+
```
291+
</TabItem>
292+
</Tabs>
278293

279294
The S3 Docker image has similar parity with the S3 APIs supported by LocalStack Docker image.
280-
You can use similar [configuration options]({{< ref "configuration/#s3" >}}) to alter the behaviour of the S3 Docker image, such as `DEBUG` or `S3_SKIP_SIGNATURE_VALIDATION`.
295+
You can use similar [configuration options](/aws/capabilities/config/configuration/#s3) to alter the behaviour of the S3 Docker image, such as `DEBUG` or `S3_SKIP_SIGNATURE_VALIDATION`.
281296

282-
{{< callout >}}
297+
:::note
283298
The S3 Docker image does not support persistence, and all data is lost when the container is stopped.
284299
To use persistence or save the container state as a Cloud Pod, you need to use the [`localstack/localstack-pro`](https://hub.docker.com/r/localstack/localstack-pro) image.
285-
{{< /callout >}}
300+
:::
286301

287302
## SSE-C Encryption
288303

@@ -303,10 +318,10 @@ However, LocalStack does not support the actual encryption and decryption of obj
303318

304319
## Resource Browser
305320

306-
The LocalStack Web Application provides a [Resource Browser]({{< ref "resource-browser" >}}) for managing S3 buckets & configurations.
321+
The LocalStack Web Application provides a [Resource Browser](/aws/capabilities/web-app/resource-browser) for managing S3 buckets & configurations.
307322
You can access the Resource Browser by opening the LocalStack Web Application in your browser, navigating to the **Resources** section, and then clicking on **S3** under the **Storage** section.
308323

309-
<img src="s3-resource-browser.png" alt="S3 Resource Browser" title="S3 Resource Browser" width="900" />
324+
![S3 Resource Browser](/images/aws/s3-resource-browser.png)
310325

311326
The Resource Browser allows you to perform the following actions:
312327

@@ -324,4 +339,4 @@ The following code snippets and sample applications provide practical examples o
324339
- [Serverless Transcription application using Transcribe, S3, Lambda, SQS, and SES](https://github.com/localstack/sample-transcribe-app)
325340
- [Query data in S3 Bucket with Amazon Athena, Glue Catalog & CloudFormation](https://github.com/localstack/query-data-s3-athena-glue-sample)
326341
- [Serverless Image Resizer with Lambda, S3, SNS, and SES](https://github.com/localstack/serverless-image-resizer)
327-
- [Host a static website locally using Simple Storage Service (S3) and Terraform with LocalStack]({{< ref "s3-static-website-terraform" >}})
342+
- [Host a static website locally using Simple Storage Service (S3) and Terraform with LocalStack]()

0 commit comments

Comments
 (0)