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.