Coder Social home page Coder Social logo

ausg-6th-small-chat-awscli's Introduction

ausg-6th-small-chat-awscli

Here introduces some useful cli snippets & scenarios when using awscli. Presentation (Korean) presented on 2022-11-14.

Table of Contents

First awscli output

The example below is a bit poor to use. JSON is great, but a bit tricky to deal with in the world of shell scripting.

$ aws ecr list-images --repository-name curl
{
    "imageIds": [
        {
            "imageDigest": "sha256:71cf92d...",
            "imageTag": "v1.5"
        },
        {
            "imageDigest": "sha256:5ddbcd0",
            "imageTag": "infinity"
        }
    ]
}

Using output option

There is an option to change output in plain text or yaml, but it is still a bit difficult.

$ aws ecr list-images --repository-name curl --output text
IMAGEIDS        sha256:71cf92d... v1.5
IMAGEIDS        sha256:5ddbcd0... infinity

$ aws ecr list-images --repository-name curl --output yaml
imageIds:
- imageDigest: sha256:71cf92d...
  imageTag: v1.5
- imageDigest: sha256:5ddbcd0...
  imageTag: infinity

Extract fields (jq)

Using jq? However, CI/CD may not have jq. You may not want to install jq separately. Is there any simpler way?

$ aws ecr list-images --repository-name curl | jq '.imageIds[].imageTag'
"v1.5"
"infinity"

Extract fields (query)

That's the awscli query option.

$ aws ecr list-images --repository-name curl --query 'imageIds[].imageTag'
[
    "v1.5",
    "infinity"
]

$ aws ecr list-images --repository-name curl --query 'imageIds[].[imageTag]' --output text
v1.5
infinity

More usecases

Great.

$ for arn in $(aws ecr describe-repositories \
        --query 'repositories[].[repositoryArn]' \
        --output text); do
    echo "[info] processing $arn"
    aws ecr tag-resource --resource-arn "$arn" --tags "user:Company=global"
done

[info] processing arn:aws:ecr:ap-northeast-2:***:repository/curl
[info] processing arn:aws:ecr:ap-northeast-2:***:repository/openjdk
...

Referenecs

Below document contains all about awscli output filtering ways. There also awscli server-side filtering is available. (when the api supports)

ausg-6th-small-chat-awscli's People

Contributors

sudosubin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.