Skip to content

sam package pollutes stdout with s3uploader progress bar #970

Closed

Description

@rlister

Description

The s3uploader code in sam package attempts to display upload progress on stdout. In a tty, this is deleted using terminal escapes, and leaves just a blank line at the head of the output json template. However, when invoked programmatically and streamed into a string, the Uploading to ... message remains, leading to invalid json.

Steps to reproduce

$ sam build --use-container
$ ruby -e 'puts %x[sam package --s3-bucket <mybucket>]' | head -2
Uploading to eda44a9c3cdb9f3ef6d46e923fff7b3d  612944 / 612944.0  (100.00%)
AWSTemplateFormatVersion: 2010-09-09

Expected result

Programs writing machine-readable output on stdout should respect unix conventions and be usable in pipeline and non-tty applications. UI elements that depend on ttys are a surprising result for the user.

The progress bar seems rather unnecessary in this application and could probably be removed. A workaround might be to use stderr for this output, or perhaps provide clean output by default, with the progress bar UI element shown with a command-line options.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: macOS + homebrew
  2. sam --version: SAM CLI, version 0.10.0

Activity

  1. chrisoverzero commented on Jan 30, 2019

    @chrisoverzero
    Contributor

    Is this output that you are using in some way—such as > redirecting to a file—or is this an appeal to UNIXy correctness?

    If you are attempting to use the output of sam package, you should consider the --output-template-file parameter. If the latter, then I mostly agree.

  2. rlister commented on Jan 30, 2019

    @rlister
    Author

    Is this output that you are using in some way—such as > redirecting to a file—or is this an appeal to UNIXy correctness?

    It is both :-)

    I hit the problem because I have extensive ruby tooling around cloudformation (to do things such as managing sibling stacks, resource discovery, etc) and am shelling out to sam in order to generate templates for my tools to handle (and ultimately hand off to the cloudformation SDK). In this context, I want to read the template stdout into a variable, and the behavior of sam was surprisingly different from the (observed) output in a terminal.

    As an old unix graybeard, I also respect the purity of the pipeline and enjoy tools that behave well when hooking up stdin and stdout. I expect these damn kids with their progress bars and other fancy UI elements to get off my lawn (and possibly go and put them in stderr, from whence I can redirect them to /dev/null).

    If you are attempting to use the output of sam package, you should consider the --output-template-file parameter. If the latter, then I mostly agree.

    Yes, I am using this as a workaround, writing to a tmpfile and reading back in. It offends my OCD, but we have SSDs and I have perpetrated far worse things in my time.

  3. rlister commented on Jan 30, 2019

    @rlister
    Author

    Additionally, I was just looking at logs from my Codebuild:

    [Container] 2019/01/30 19:59:27 Running command sam package --s3-bucket ${S3_BUCKET} --output-template-file ../package.yaml 
     
    Uploading to dec13a9e641dbe847a060bcb143fc4c8  9090 / 9090.0  (100.00%) 
    Uploading to 4af8bde2dbcf792c8de017306b522a79  262144 / 46315080.0  (0.57%) 
    ...
    ... repeated for the next 185 lines of my log ...
    ...
    Successfully packaged artifacts and wrote output template to file ../package.yaml. 
    

    It would be nice to have an option to silence the 185 lines of Uploading in these non-terminal scenarios.

  4. added
    area/package
    on Apr 23, 2019
  5. chizou commented on Jul 11, 2019

    @chizou

    On this note, can the documentation be updated so that --output-template-file is actually listed as an option?

  6. karl-barbour commented on Nov 13, 2019

    @karl-barbour

    Hitting this problem as I run sam package in an Azure DevOps pipeline. I specifically have the option ticked to 'fail on stderr', as we don't want to deploy a bad package.

    I redirected stderr to a file and see this:

    2019-11-13 22:31:30 Found credentials in shared credentials file: ~/.aws/credentials
    
    Uploading to samartifacts/2dea646d8bf2d6d7525f49c707d478fb  262144 / 2974693.0  (8.81%)
    Uploading to samartifacts/2dea646d8bf2d6d7525f49c707d478fb  524288 / 2974693.0  (17.62%)
    Uploading to samartifacts/2dea646d8bf2d6d7525f49c707d478fb  786432 / 2974693.0  (26.44%)
    Uploading to samartifacts/2dea646d8bf2d6d7525f49c707d478fb  1048576 / 2974693.0  (35.25%)
    Uploading to samartifacts/2dea646d8bf2d6d7525f49c707d478fb  1310720 / 2974693.0  (44.06%)
    Uploading to samartifacts/2dea646d8bf2d6d7525f49c707d478fb  1572864 / 2974693.0  (52.87%)
    Uploading to samartifacts/2dea646d8bf2d6d7525f49c707d478fb  1835008 / 2974693.0  (61.69%)
    Uploading to samartifacts/2dea646d8bf2d6d7525f49c707d478fb  2097152 / 2974693.0  (70.50%)
    Uploading to samartifacts/2dea646d8bf2d6d7525f49c707d478fb  2359296 / 2974693.0  (79.31%)
    Uploading to samartifacts/2dea646d8bf2d6d7525f49c707d478fb  2621440 / 2974693.0  (88.12%)
    Uploading to samartifacts/2dea646d8bf2d6d7525f49c707d478fb  2883584 / 2974693.0  (96.94%)
    Uploading to samartifacts/2dea646d8bf2d6d7525f49c707d478fb  2974693 / 2974693.0  (100.00%)
    Uploading to samartifacts/cb114a5066b849e5880c7615d8e900f8  262144 / 2482489.0  (10.56%)
    Uploading to samartifacts/cb114a5066b849e5880c7615d8e900f8  524288 / 2482489.0  (21.12%)
    Uploading to samartifacts/cb114a5066b849e5880c7615d8e900f8  786432 / 2482489.0  (31.68%)
    Uploading to samartifacts/cb114a5066b849e5880c7615d8e900f8  1048576 / 2482489.0  (42.24%)
    Uploading to samartifacts/cb114a5066b849e5880c7615d8e900f8  1310720 / 2482489.0  (52.80%)
    Uploading to samartifacts/cb114a5066b849e5880c7615d8e900f8  1572864 / 2482489.0  (63.36%)
    Uploading to samartifacts/cb114a5066b849e5880c7615d8e900f8  1835008 / 2482489.0  (73.92%)
    Uploading to samartifacts/cb114a5066b849e5880c7615d8e900f8  2097152 / 2482489.0  (84.48%)
    Uploading to samartifacts/cb114a5066b849e5880c7615d8e900f8  2359296 / 2482489.0  (95.04%)
    Uploading to samartifacts/cb114a5066b849e5880c7615d8e900f8  2482489 / 2482489.0  (100.00%)
    Uploading to samartifacts/462357a0bf0c716d631d646784cd1f89  262144 / 456581.0  (57.41%)
    Uploading to samartifacts/462357a0bf0c716d631d646784cd1f89  456581 / 456581.0  (100.00%)
    

    Surely this should be in stdout, not stderr?

    I can workaround by redirecting stderr to stdout, but I guess I'll have to error check the package in other ways. Doable but not ideal.

    What was the design decision around outputting the above to stderr? Is it needed?

    EDIT:

    Appears the culprit is at https://github.com/awslabs/aws-sam-cli/blob/7cbcfffa4c4c8eac237cfa8613912504d61a8d01/samcli/lib/package/s3_uploader.py#L207 - I can't see an obvious reason for stderr here.

  7. jfuss commented on Nov 13, 2019

    @jfuss
    Contributor

    In our recent port and moving off of AWS CLI, we moved this output from STDOUT to STDERR (for package, I don't think we have yet updated build). We moved it for the reasons @rlister mentioned above.

    @karl-barbour Assuming unix/linux here but you should use echo $? to see the status of the previously run command. I think that is what you want instead of relying out output to STDOUT or STDERR by the CLI.

    Closing this as we addressed the initially issue reported by @rlister in v0.31.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/packagetype/ux

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions