如何抑制 aws lambda cli 输出

bio*_*aks 11 aws-cli aws-lambda

I want to use aws lambda update-function-code command to deploy the code of my function. The problem here is that aws CLI always prints out some information after deployment. That information contains sensitive information, such as environment variables and their values. That is not acceptable as I'm going to use public CI services, and I don't want that info to become available to anyone. At the same time I don't want to solve this by directing everything from AWS command to /dev/null for example as in this case I will lose information about errors and exceptions which will make it harder to debug it if something went. What can I do here?

p.s. SAM is not an option, as it will force me to switch to another framework and completely change the workflow I'm using.

Bra*_*ler 2

您可以通过将这些值替换为来定位您想要抑制的输出jq

例如,如果您有 cli 命令的输出,如下所示:

{
  "FunctionName": "my-function",
  "LastModified": "2019-09-26T20:28:40.438+0000",
  "RevisionId": "e52502d4-9320-4688-9cd6-152a6ab7490d",
  "MemorySize": 256,
  "Version": "$LATEST",
  "Role": "arn:aws:iam::123456789012:role/service-role/my-function-role-uy3l9qyq",
  "Timeout": 3,
  "Runtime": "nodejs10.x",
  "TracingConfig": {
      "Mode": "PassThrough"
  },
  "CodeSha256": "5tT2qgzYUHaqwR716pZ2dpkn/0J1FrzJmlKidWoaCgk=",
  "Description": "",
  "VpcConfig": {
      "SubnetIds": [],
      "VpcId": "",
      "SecurityGroupIds": []
  },
  "CodeSize": 304,
  "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function",
  "Handler": "index.handler",
  "Environment": {
    "Variables": {
      "SomeSensitiveVar": "value",
      "SomeOtherSensitiveVar": "password"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

jq仅当键存在时,您才可以通过管道将其传递给并替换值:

aws lambda update-function-code <args> | jq '
  if .Environment.Variables.SomeSensitiveVar? then .Environment.Variables.SomeSensitiveVar = "REDACTED" else . end |
  if .Environment.Variables.SomeRandomSensitiveVar? then .Environment.Variables.SomeOtherSensitiveVar = "REDACTED" else . end'
Run Code Online (Sandbox Code Playgroud)

您知道哪些数据是敏感数据,并且需要对其进行适当的设置。您可以在cli 文档中查看返回数据的示例,API 文档也有助于理解结构的外观。