Skip to content

cloudformation package stops escaping non-ASCII/emoji characters in YAML double-quoted strings starting from 2.34.13` #10185

@rkamach-smtc

Description

@rkamach-smtc

Describe the bug

aws cloudformation package stopped escaping non-ASCII/emoji characters in YAML double-quoted strings starting from 2.34.13. Older versions serialized them as YAML unicode escape sequences (e.g. \U0001F6A8), newer versions write raw UTF-8 bytes instead, which CloudFormation cannot display correctly.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

Emoji characters inside Fn::Sub are serialized as YAML unicode escapes (2.34.12 output):

}}{{ if eq .Status `firing` }}\U0001F6A8{{ else if eq .Status `resolved` }}\U0001F7E2{{ else }}\U0001F7E1{{ end }}{{ end }}

Current Behavior

Starting from 2.34.13, emojis are written as raw UTF-8 bytes (2.34.22 output):

}}{{ if eq .Status `firing` }}🚨{{ else if eq .Status `resolved` }}🟢{{ else }}🟡{{ end }}{{ end }}

This causes CloudFormation Stack to display ? instead of emojis in the console and via aws cloudformation get-template.

Reproduction Steps

  1. Create dummy-cf.yaml:
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
  EnvName:
    Type: String
    Default: test
Resources:
  TestResource:
    Type: AWS::SSM::Parameter
    Properties:
      Name: !Sub "${EnvName}-test"
      Type: String
      Value:
        Fn::Sub:
          - |
            template_files:
              slack_template: |
                {{ define "sns.slack.status_emoji" }}{{ if eq .Status `firing` }}🚨{{ else if eq .Status `resolved` }}🟢{{ else }}🟡{{ end }}{{ end }}
                {{ define "sns.slack.message" }}
                {{- $envName := printf "%s" "${EnvName}" -}}
                {{- $queryExprTemplated := reReplaceAll "\\]" "%5D" (
                    reReplaceAll "\\[" "%5B" (
                    reReplaceAll "=" "%3D" (
                    reReplaceAll "\\}" "%7D" (
                    reReplaceAll "\\{" "%7B" (
                    reReplaceAll ">" "%3E" (
                    reReplaceAll "<" "%3C" (
                    reReplaceAll " " "%20" (
                    reReplaceAll "\"" "%22" (
                    reReplaceAll "'" "%27" (
                      $envName
                    )))))))))) }}
                {{ end }}
          - {}
  1. Run:
docker run --rm -v $(pwd):/workspace amazon/aws-cli:2.34.12 \
  cloudformation package \
  --template-file /workspace/dummy-cf.yaml \
  --output-template-file /workspace/packaged-2.34.12.yml \
  --s3-bucket dummy-bucket

docker run --rm -v $(pwd):/workspace amazon/aws-cli:2.34.22 \
  cloudformation package \
  --template-file /workspace/dummy-cf.yaml \
  --output-template-file /workspace/packaged-2.34.22.yml \
  --s3-bucket dummy-bucket

diff packaged-2.34.12.yml packaged-2.34.22.yml
  1. Diff output:
<           \ }}{{ if eq .Status `firing` }}\U0001F6A8{{ else if eq .Status `resolved`\
<           \ }}\U0001F7E2{{ else }}\U0001F7E1{{ end }}{{ end }}\n    {{ define "sns.slack.message"\
---
>           \ }}{{ if eq .Status `firing` }}🚨{{ else if eq .Status `resolved` }}🟢{{\
>           \ else }}🟡{{ end }}{{ end }}\n    {{ define "sns.slack.message" }}\n \

Possible Solution

Most likely same root cause as #10156 — the ruamel.yaml upgrade from 0.17.21 to 0.19.1 introduced in 2.34.13 alongside the Python 3.14.3 interpreter upgrade. The new version likely changed how non-ASCII characters are handled during YAML serialization.

Additional Information/Context

Functionally emojis still work — downstream services (tested on AMP Alermanager) receive and display them correctly. The impact is that CloudFormation shows ? in the console and get-template output, making it hard to verify what is actually deployed.

CLI version used

2.34.22

Environment details (OS name and version, etc.)

Reproduced using official amazon/aws-cli Docker images on macOS

Metadata

Metadata

Labels

bugThis issue is a bug.cloudformationcloudformation package-deployp2This is a standard priority issuepotential-regressionMarking this issue as a potential regression to be checked by team memberresponse-requestedWaiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions