Search code examples
amazon-web-servicesaws-lambdamicroservicesserverless-frameworkaws-sam

How can i use AWS SAM Template File separation like Serverless Framework use?


I have used Serverless Framework very well.

At the time using it i remember using one main file called serverless.yml and after that for each service i use function.yml and refering this file to the main serverless.yml.

So now i am working with AWS SAML and i can't find anything useful related to file separation.

AWS SAM template file gets very large for a big project is there any ways to make file serparation for each of microservice i have rather than making SAM template for each service ?

For Serveless Framework example would be:

serverless.yml

service: thoughtfull
frameworkVersion: "3"
useDotenv: true

functions:
  - ${file(./services/authentication/functions.yml)}
  - ${file(./services/other_service/functions.yml)}

services/authentication/functions.yml

login:
  image:
    name: latest
    command: authentication/login.lambda_handler
    entryPoint:
      - "/lambda-entrypoint.sh"
  events:
    - http:
        path: auth/login
        method: post
        cors: true

Can i get this kind of freedom in AWS SAM template ?

How can i achive this kind of solution in AWS SAM template for project ?

I have searched a lot for this but couldn't find anything useful. As i explained in the question i want to achieve AWS SAM template file separation.

I am hoping somebody worked with AWS SAM template could give me a good insight in how to make it so that it can be maintainable and easy for CI/CD too.


Solution

  • I have desired this as well and have not found a way to accomplish it in the same fashion as Serverless. That being said, unlike Serverless, you can reference different files with the cli commands with --template [template name], so in terms of CI/CD, you could theoretically break templates into separate standalone templates and then have your CI/CD deploy each separately; the downside is you make multiple cloudformation stacks, but it could be useful in some use cases, especially if you're deploying cloudformation stack sets and you want to break up different infrastructure.