I have this for example in my template:
ApiGatewayRestApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: MyApi
Description: My AWS API Gateway config
Body:
# INSERT swagger.yml content here
Is there some cloudformation function I can use to read swagger.yml in or attach it under "Body:"? So I can keep it in another file and my template doesn't become huge.
CloudFormation does not transform, modify, or redact any information you include in the Metadata section. For more information, see Metadata. The Outputs template section.
You can author AWS CloudFormation templates in JSON or YAML formats. We support all AWS CloudFormation features and functions for both formats, including in AWS CloudFormation Designer.
To import existing resources into a CloudFormation stack, you need to provide: A template that describes the entire stack, including both the resources to import and (for existing stacks) the resources that are already part of the stack. Each resource to import must have a DeletionPolicy attribute in the template.
According to the docs, Conditions should be used at the top level of the resource you want to conditionally create. Putting a Condition inside the Instance UserData section isn't supported. To use Conditions in your situation, you'd want separate Resources conditionally created based on the Parameter.
Create a stack from existing resources using the AWS Management Console. Sign in to the AWS Management Console and open the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation . On the Stacks page, choose Create stack, and then choose With existing resources (import resources).
Parameters (optional) Values to pass to your template at runtime (when you create or update a stack). You can refer to parameters from the Resources and Outputs sections of the template.
There's a Fn::Transform function that allows you to call different Cloudformation macros to process your templates. One of those macros is AWS::Include
Heres an example:
Resources:
APIGateway:
Fn::Transform:
Name: AWS::Include
Parameters:
Location:
Fn::Sub: s3://partials-bucket/${PartialsEnv}/resources/api-gateway.yaml
Here api-gateway.yaml
will have the full definition of your resource.
You can use this function in the same way as other intrinsic functions. The only caveat is AWS::Include
will only work with files hosted in S3 so you'll need to upload your partials separatedly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With