# Configure S3 in Serverless

**URL:** <https://discourse.sst.dev/t/configure-s3-in-serverless/163>\
**Category:** Chapter Comments\
**Created:** [May 9, 2018, 11:12pm UTC](https://discourse.sst.dev/t/configure-s3-in-serverless/163 "2018-05-09T23:12:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [May 9, 2018, 11:12pm UTC](https://discourse.sst.dev/t/configure-s3-in-serverless/163/1 "2018-05-09T23:12:27Z")

</div>

Link to chapter - [https://serverless-stack.com/chapters/configure-s3-in-serverless.html](https://serverless-stack.com/chapters/configure-s3-in-serverless.html)

---

<div class="post-metadata">

**Author:** ![7hibault](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/7hibault/32/382_2.png) [@7hibault](https://discourse.sst.dev/u/7hibault)\
**Post date:** [April 16, 2019, 4:33pm UTC](https://discourse.sst.dev/t/configure-s3-in-serverless/163/2 "2019-04-16T16:33:35Z")

</div>

Don’t we miss 2 things here?

1. IAM configuration to give access to the attachment bucket

2. S3 bucket to deploy the front-end

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [April 22, 2019, 12:33am UTC](https://discourse.sst.dev/t/configure-s3-in-serverless/163/3 "2019-04-22T00:33:32Z")

</div>

The IAM configuration is added in this chapter - [https://serverless-stack.com/chapters/configure-cognito-identity-pool-in-serverless.html](https://serverless-stack.com/chapters/configure-cognito-identity-pool-in-serverless.html)

The frontend app in this section uses Netlify instead of S3.

---

<div class="post-metadata">

**Author:** ![namelesswc](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/namelesswc/32/620_2.png) [@namelesswc](https://discourse.sst.dev/u/namelesswc)\
**Post date:** [October 10, 2019, 2:51pm UTC](https://discourse.sst.dev/t/configure-s3-in-serverless/163/4 "2019-10-10T14:51:55Z")

</div>

How can we reference the bucket name in our code?

Is there really not a better way to get bucket names? I’d like to have different versions of my bucket for dev and prod and be able to reference it inside my functions.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [October 12, 2019, 12:11am UTC](https://discourse.sst.dev/t/configure-s3-in-serverless/163/5 "2019-10-12T00:11:41Z")

</div>

Bucket names need to be globally unique, so in this case it’s better if AWS generates them.

But your question is a bit more of an advanced topic. You want to be able to “parameterize” your bucket name and use that in a Lambda function. We talk about part of this in the new best practices section of the guide - [https://serverless-stack.com/chapters/s3-as-a-serverless-service.html](https://serverless-stack.com/chapters/s3-as-a-serverless-service.html). You’ll notice how we export the bucket name there and it includes the stage name as well.

Finally, to use this exported value in your Lambda function you’ll need to add this to the `environment` block in your `serverless.yml`.

```auto
environment:
    bucketName:
      'Fn::ImportValue': ${self:custom.stage}-ExtAttachmentsBucketArn

```

And then `process.env.bucketName` will give you this value in your function.

---

<div class="post-metadata">

**Author:** ![namelesswc](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/namelesswc/32/620_2.png) [@namelesswc](https://discourse.sst.dev/u/namelesswc)\
**Post date:** [October 25, 2019, 12:08pm UTC](https://discourse.sst.dev/t/configure-s3-in-serverless/163/6 "2019-10-25T12:08:30Z")

</div>

Thank you jayair. The content has grown quite a bit and I must have missed this chapter.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [October 26, 2019, 2:37am UTC](https://discourse.sst.dev/t/configure-s3-in-serverless/163/7 "2019-10-26T02:37:41Z")

</div>

Yeah we have a new section in the guide.

---

<div class="post-metadata">

**Author:** ![faysal-ishtiaq](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/faysal-ishtiaq/32/755_2.png) [@faysal-ishtiaq](https://discourse.sst.dev/u/faysal-ishtiaq)\
**Post date:** [February 6, 2020, 11:50am UTC](https://discourse.sst.dev/t/configure-s3-in-serverless/163/8 "2020-02-06T11:50:04Z")

</div>

If I want to allow my users upload large files, i.e. several GB, what should be the MaxAge parameter value?

If I want to give my users access token and secret keys which can be used to upload data in a subdirectory, i.e. - Fn::GetAtt: [UserDataS3Bucket, Arn]  
- ‘/private/’  
- ‘$’  
- ‘{[cognito-identity.amazonaws.com](http://cognito-identity.amazonaws.com):sub}/_ **raw-data** _’  
how do I generate it?

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [February 10, 2020, 7:18pm UTC](https://discourse.sst.dev/t/configure-s3-in-serverless/163/9 "2020-02-10T19:18:51Z")

</div>

Hmm I’m not entirely sure about this. Is there a doc on uploading large files?
