0

I can get the details with

$ aws lambda get-function --function-name random_number
{
    "Configuration": {
        "FunctionName": "random_number",
        "FunctionArn": "arn:aws:lambda:us-east-2:193693970645:function:random_number",
        "Runtime": "ruby2.5",
        "Role": "arn:aws:iam::193693970645:role/service-role/random_number-role-8cy8a1a7",
        ...

But how can get just a couple of fields like function name ?

I tried:

$ aws lambda get-function --function-name random_number --query "Configuration[*].[FunctionName]"

but I get null

4 Answers 4

2

Your overall approach is correct, you just need to adjust the query:

$ aws lambda get-function --function-name random_number \
      --query "Configuration.FunctionName" --output text

I also added a parameter to convert the result to text, which makes processing a bit easier.

Sign up to request clarification or add additional context in comments.

Comments

1

Here is a simple awk (standard Linux gnu awk) script that does the trick: Extract the values of quoted field #3, only for line having /FunctionName/.

awk 'BEGIN {FPAT="\"[^\"]+"}/FunctionName/{print substr($3,2)}'

Piped with your initial command:

$ aws lambda get-function --function-name random_number | awk 'BEGIN {FPAT="\"[^\"]+"}/FunctionName/{print substr($3,2)}'

Comments

0

One way to achieve that is by using jq. therefore, the output must be JSON.

From the docs :

jq is like sed for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text.

Usage example :

aws lambda get-function --function-name test --output json | jq -r '.Configuration.FunctionName'

Comments

-2

Use get-function-configuration as in the following:

aws lambda get-function-configuration --function-name MyFunction --query "[FunctionName]"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.