When using AWS LocalStack, even if you create a CloudFormation stack from a YAML file, the template body is saved in JSON format

using LocalStack.

I am creating LocalStack using the following Dockercompose.

services:
  localstack:
    container_name: localstack
    image: localstack/localstack:4.0.3
    ports:
      - "127.0.0.1:4566:4566"
    environment:
      - DEBUG=1

When using LocalStack, creating a stack based on the following file and then retrieving the stack’s template body results in it being obtained in JSON format instead of YAML format. I expected it to be retrieved in YAML format. Why is this happening?

When creating a stack in a regular AWS environment using the same YAML file and then retrieving the template body, it is obtained in YAML format.

  • test/test-cloudformation.yaml
---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Resources'
Parameters:
  Env:
    Type: 'String'
    Description: 'Environment Name'
    AllowedValues:
      - 'dev'
      - 'stg'
      - 'prd'
  ResourcePrefix:
    Type: 'String'
    Description: 'Resources Prefix'
    Default: 'prefix'


Resources:
  # S3 Bucket
  S3Bucket:
    Type: 'AWS::S3::Bucket'
    DeletionPolicy: 'Retain'
    UpdateReplacePolicy: 'Retain'
    Properties:
      BucketName: !Sub '${Env}-${ResourcePrefix}-stack-test'
      VersioningConfiguration:
        Status: 'Enabled'
      PublicAccessBlockConfiguration:
        BlockPublicAcls: true
        BlockPublicPolicy: true
        IgnorePublicAcls: true
        RestrictPublicBuckets: true
  • test/parameters/test-cloudformation/test.json
[
    {
        "ParameterKey": "Env",
        "ParameterValue": "dev"
    }
]

$ aws cloudformation create-stack --region ap-northeast-1 --stack-name test-cloudfomation --endpoint-url=http://localhost:4566 --profile cfn-deploy-localstack --template-body file://test/test-cloudformation.yaml --parameters file://test/parameters/test-cloudformation/test.json
$ aws cloudformation get-template --endpoint-url=http://localhost:4566 --profile cfn-deploy-localstack --stack-name test-cloudfomation | jq -r '.TemplateBody'

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "Resources",
  "Parameters": {
    "Env": {
      "Type": "String",
      "Description": "Environment Name",
      "AllowedValues": [
        "dev",
        "stg",
        "prd"
      ]
    },
    "ResourcePrefix": {
      "Type": "String",
      "Description": "Resources Prefix",
      "Default": "prefix"
    }
  },
  "Resources": {
    "S3Bucket": {
      "Type": "AWS::S3::Bucket",
      "DeletionPolicy": "Retain",
      "UpdateReplacePolicy": "Retain",
      "Properties": {
        "BucketName": {
          "Fn::Sub": "${Env}-${ResourcePrefix}-stack-test"
        },
        "VersioningConfiguration": {
          "Status": "Enabled"
        },
        "PublicAccessBlockConfiguration": {
          "BlockPublicAcls": true,
          "BlockPublicPolicy": true,
          "IgnorePublicAcls": true,
          "RestrictPublicBuckets": true
        }
      },
      "LogicalResourceId": "S3Bucket"
    }
  },
  "StackName": "test-cloudfomation",
  "StackId": "arn:aws:cloudformation:ap-northeast-1:000000000000:stack/test-cloudfomation/c8a7a9bb",
  "Outputs": {},
  "Conditions": {},
  "Mappings": {}
}

Any assistance would be greatly appreciated.

Hi @keny1111,

I can confirm the discrepancy in the outputs and have added an item to the engineering team’s backlog for further investigation.

1 Like

Hi @Marcel

Thank you for confirming!

Also, thank you for adding it to the backlog! By the way, how long will the investigation approximately take?

My colleague has already investigated and he was provided a yaml-structured response. Therefore, we need to conduct further investigation.

Please see our documentation on different type of support at Help & Support | Docs. We do our best to resolve the issues, but we do not provide an ETA for community reports.

Note that community support is provided on a best-effort basis and is not guaranteed. Users are encouraged to help others by sharing their knowledge and experiences.

1 Like

Hi @keny1111,

We successfully reproduced the issue.

As a potential workaround, you can use deploy instead of `create-stack which will provide you with a correct YAML output.

1 Like