# AWS Serverless framework - Nested Stack

**URL:** <https://forum.serverless.com/t/aws-serverless-framework-nested-stack/9841>\
**Category:** Serverless Framework\
**Tags:** cloudformation\
**Created:** [November 13, 2019, 1:13pm UTC](https://forum.serverless.com/t/aws-serverless-framework-nested-stack/9841 "2019-11-13T13:13:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dattatrayhkulkarni](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@dattatrayhkulkarni](https://forum.serverless.com/u/dattatrayhkulkarni)\
**Post date:** [November 13, 2019, 1:13pm UTC](https://forum.serverless.com/t/aws-serverless-framework-nested-stack/9841/1 "2019-11-13T13:13:10Z")

</div>

I am using `serverless framework`

Before I deploy the serverless stack, there are some manual steps, which I need to perform -

1. Creating S3 buckets
2. Creating Cognito User Pools, App clients, etc. 3…

The ARNs of these AWS resources which are created in the above steps, are configured as environment variables in the serverless.yml file.

Apart from this, I want to avoid the possible problem of reaching the AWS cloudformation limit of 200 resources in one stack.

What is the best way/tools to split this stack into two parts?

Are there any examples, in which output of one stack is used as environment variables in the another stack?

Another option, I am thinking is to use the `Cloudformation` template, which Serverless framework creates and then use it inside a nested CF stack.

Any better options/tools?

---

<div class="post-metadata">

**Author:** ![bfieber](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/bfieber/32/653_2.png) [@bfieber](https://forum.serverless.com/u/bfieber)\
**Post date:** [November 13, 2019, 3:28pm UTC](https://forum.serverless.com/t/aws-serverless-framework-nested-stack/9841/2 "2019-11-13T15:28:22Z")

</div>

In the stack that creates the resources, export the name/arn values you need in your other stack(s):

```auto
Outputs:
  ExampleS3BucketName:
    Description: The Name of the Example S3 Bucket
    Value:
      Ref: S3BucketExample
    Export:
      Name: ${self:service}-${self:provider.stage}-ExampleS3BucketName
  ExampleS3BucketArn:
    Description: The Arn of the Example S3 Bucket
    Value:
      Fn::GetAtt: [S3BucketExample, Arn]
    Export:
      Name: ${self:service}:${self:provider.stage}:ExampleS3BucketArn

```

Then in the serverless.yml of the stacks that need the values, import via [${cf:…}](https://serverless.com/framework/docs/providers/aws/guide/variables#reference-cloudformation-outputs) or [Fn::Import](https://serverless.com/framework/docs/providers/aws/guide/variables#reference-cloudformation-outputs) the properties you need. (arn to grant iamRolePermissions, name to access it.

```auto
custom:
  imported-name: ${cf:myservice-dev-ExampleS3BucketName}
  imported-arn:
    Fn::ImportValue: myservice:dev:ExampleS3BucketArn

```

Hope it helps!

---

<div class="post-metadata">

**Author:** ![mailletf](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/mailletf/32/5115_2.png) [@mailletf](https://forum.serverless.com/u/mailletf)\
**Post date:** [January 22, 2021, 1:23am UTC](https://forum.serverless.com/t/aws-serverless-framework-nested-stack/9841/3 "2021-01-22T01:23:14Z")

</div>

I would highly recommend you take an infrastructure as code approach. I’m personally using AWS CDK.

Take a look at this great tutorial for an example of how you could do it: [Getting Production Ready | Serverless Stack](https://serverless-stack.com/chapters/getting-production-ready.html)

---

<div class="post-metadata">

**Author:** ![mnapoli](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/mnapoli/32/6575_2.png) [@mnapoli](https://forum.serverless.com/u/mnapoli)\
**Post date:** [February 8, 2022, 1:40pm UTC](https://forum.serverless.com/t/aws-serverless-framework-nested-stack/9841/4 "2022-02-08T13:40:06Z")

</div>

Hey everyone, we are exploring solutions for these exact scenarios: deploying resources (e.g. database, SQS, S3…) separately from the serverless service/API, and easily integrate the ARNs/IDs of those resources.

We’re looking for users to give feedback on that feature (and possibly beta test it). If you are interested, post a reply here or send me an email: [matthieu.napoli@serverless.com](mailto:matthieu.napoli@serverless.com)
