aws / aws/aws-cli

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

Open
#10,185 5 comments 0 reactions 0 assignees View on GitHub
bug cloudformation cloudformation package-deploy p2 regression
Dominant language
Python
Stars
17.3k
Forks
4.6k
Avg merge
1d 2h
Merged PRs (30d)
13

Description

### 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

- [x] 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`:

```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 }}
- {}
```

2. Run:

```bash
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
```

3. Diff output:

```diff
< \ }}{{ 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.