I want to write my cloud formation yml file in a different file and load them separately. It is easy to do it in the serverless framework but I couldn\'t figure it out how t
you can use the Location
property ( https://docs.aws.amazon.com/de_de/serverless-application-model/latest/developerguide/serverless-sam-template-nested-applications.html)
In your case should be something like
template.yml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Sample SAM Template
# Create our resources with separate CloudFormation templates resources:
Resources:
yourApplicationAliasName:
Type: AWS::Serverless::Application
Properties:
# Lambda function
Location: ./resources/lambda-functions.yml
and the lambda-functions.yml file
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: AWS Lambda function.
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: hello-world/
Handler: app.lambdaHandler
Runtime: nodejs12.x
Events:
HelloWorld:
Type: Api
Properties:
Path: /helloworld
Method: get
try to use be sam command for packaging as below:
sam package --template template.yml --output-template-file outputtemplate.yml --s3-bucket your-bucket-name
then you need to deploy it:
sam deploy --template-file outputtemplate.yml --stack-name your-bucket-name --capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND
** do not forget to remove your previous stack if there is any.
Thx!.........
@amir would be curious to hear from you as to whether you sorted this out. For those searching for this, as far as I've seen, this won't work because nested stacks don't appear to support transforms (yet) in CloudFormation.
This issue mentions that nested stacks can't use transforms like SAM, and in this closed GitHub issue, one of the maintainers of the AWS SAM CLI noted "Closing as we don't yet support Nested Templates in SAM build or any other commands except package. We should create a general issue for this support."
Please give thumbs up to the CF roadmap to ask AWS to support this.