AWS Serverless framework - Nested Stack

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?

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

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:…} or Fn::Import the properties you need. (arn to grant iamRolePermissions, name to access it.

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

Hope it helps!

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

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