question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AWS CloudFormation stack fails with "UnicodeDecodeError"

See original GitHub issue

I have been attempting to spin up the CloudFormation stack provided here. This intermittently fails and succeeds, I’m not sure why it sometimes does and sometimes doesn’t work.

When it fails, it’s because the EC2 instance fails to initialize. The most promising section I can find from the EC2 logs shows the following:

Traceback (most recent call last):
  File "/usr/lib64/python2.7/logging/__init__.py", line 891, in emit
    stream.write(fs % msg.encode("UTF-8"))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 49: ordinal not in range(128)
Logged from file util.py, line 476
Traceback (most recent call last):
  File "/usr/lib64/python2.7/logging/__init__.py", line 891, in emit
    stream.write(fs % msg.encode("UTF-8"))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 71: ordinal not in range(128)
Logged from file util.py, line 476
[   72.975338] EXT4-fs (dm-3): mounted filesystem with ordered data mode. Opts: (null)
Error occurred during build: Command 04InstallECSAdditions failed

The line EXT4-fs (dm-3): mounted filesystem with ordered data mode is repeated about 100 times in the real logs (below), I’ve just abridged it here for clarity. Anyway, the main thing this tells us that it’s failing during step 04 of the EC2 startup script, which does the following:

04InstallECSAdditions:
  command:
    Fn::If:
      - UseCromwell
      - !Join [" ", ["sh", "/opt/ecs-additions/ecs-additions-cromwell.sh"]]
      - echo "OK"
  env:
    PATH: "/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin"

My best guess as to what is happening, is this blog post, which suggests:

Apparently cfn-init has a limit on the amount of output it can process from a command, and I was pushing that limit.

I suspect the reason for the UTF8 error is that the output was truncated between two bytes or something, and when the parser underneath cfn-init tried to parse it, it encountered what appeared to be an invalid UTF8 character.

So perhaps the reason this issue is intermittent is because the length of the logs from this command are occasionally too long for the cfn-init script? Or this might be a red herring.

To aid with debugging, here are some useful logs

  • ec2_log.txt: This is the console output from the EC2 instance that failed. I’ve censored out some of the key data, just in case any of it involves my own public key (probably unnecessary, but I doubt it’s related)
  • stack_description.json.txt: The output from aws cloudformation describe-stacks on the stack I spun up. This should give you the exact parameters I used when it last failed.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

13reactions
Mahesh81commented, Oct 30, 2019

Can you please share the fix, i face the same issue in my template

0reactions
seth-xdamcommented, Jun 27, 2019

@wleepang Could you share what change you made to fix the problem? I’m getting the same error on my own CloudFormation template.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python encoding error? UnicodeDecodeError: 'ascii' codec ...
Your file is encoded, that means it represents unicode in a defined way. You use some literal strings (e.g. XYZ ), which shall...
Read more >
Troubleshooting CloudFormation - AWS Documentation
If AWS CloudFormation fails to create, update, or delete your stack, you can view error messages or logs to help you learn more...
Read more >
Resolve the "Custom Named Resource already exists in stack ...
My AWS CloudFormation stack fails to create a resource, and I receive an error message telling me that my resource already exists in...
Read more >
Resolve the "Internal Failure" error in CloudFormation
If you're creating or updating your CloudFormation stack, you can receive an "Internal Failure" error when an operation on a resource fails.
Read more >
Update CloudFormation stacks that are failing because of ...
I manually deleted a resource that was created by one of my AWS CloudFormation stacks, and now my stack won't update. Short description....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found