执行 bash 时发生 ValidationException

huangapple go评论54阅读模式
英文:

ValidationException while executing bash

问题

Here i am trying to retrieve latest ami id for k8s worker node.

我在尝试检索最新的 K8s 工作节点 AMI ID。

i have written a bash script for the same, every time i run this script it return errors.

我编写了一个相同的 bash 脚本,每次运行它都会返回错误。

Please set VERSION=v1.23 before running script

请在运行脚本之前设置 VERSION=v1.23

note: when we run the command individually it works.

注意:当我们单独运行命令时,它是有效的。

#!/bin/bash

VERSION=$1

SOURCE_AMI_ID=$(aws ssm get-parameter --name /aws/service/eks/optimized-ami/${VERSION}/amazon-linux-2/recommended/image_id --region us-west-2 --query "Parameter.Value" --output text)
SOURCE_AMI_NAME=$(aws ec2 describe-images --image-ids ${SOURCE_AMI_ID} | jq -r '.Images[0].Name')
AMI_NAME=$(echo "${SOURCE_AMI_NAME}" | sed 's/amazon/kube-infra/g')
jq -n
--arg source_ami_id "${SOURCE_AMI_ID}"
--arg source_ami_name "${SOURCE_AMI_NAME}"
--arg cp_ami_name "${CP_AMI_NAME}"
'{source_ami_id: $source_ami_id, source_ami_name: $source_ami_name, ami_name: $ami_name}'

error:

An error occurred (ValidationException) when calling the GetParameter operation: Parameter name: can't be prefixed with "ssm" (case-insensitive). If formed as a path, it can consist of sub-paths divided by slash symbol; each sub-path can be formed as a mix of letters, numbers and the following 3 symbols .-_

错误:

调用 GetParameter 操作时发生错误(ValidationException):参数名称不能以 "ssm" 为前缀(不区分大小写)。如果形成为路径,则可以由斜杠符号分隔的子路径组成;每个子路径可以由字母、数字和以下 3 个符号 .-_ 的混合形成。

how i am running the above script

% ./build-versions.sh

我如何运行上述脚本:

% ./build-versions.sh

An error occurred (ValidationException) when calling the GetParameter operation: Parameter name: can't be prefixed with "ssm" (case-insensitive). If formed as a path, it can consist of sub-paths divided by slash symbol; each sub-path can be formed as a mix of letters, numbers and the following 3 symbols .-_
发生错误(ValidationException):调用 GetParameter 操作时发生错误:参数名称不能以 "ssm" 为前缀(不区分大小写)。如果形成为路径,则可以由斜杠符号分隔的子路径组成;每个子路径可以由字母、数字和以下 3 个符号 .-_ 的混合形成。

英文:

Here i am trying to retrieve latest ami id for k8s worker node.

i have written a bash script for the same, every time i run this script it return errors.

Please set VERSION=v1.23 before running script

note: when we run the command individually it works.

#!/bin/bash

VERSION=$1

SOURCE_AMI_ID=$(aws ssm get-parameter --name /aws/service/eks/optimized-ami/${VERSION}/amazon-linux-2/recommended/image_id --region us-west-2 --query "Parameter.Value" --output text)
SOURCE_AMI_NAME=$(aws ec2 describe-images --image-ids ${SOURCE_AMI_ID} | jq -r '.Images[0].Name')
AMI_NAME=$(echo "${SOURCE_AMI_NAME}" | sed 's/amazon/kube-infra/g')
jq -n \
        --arg source_ami_id "${SOURCE_AMI_ID}" \
        --arg source_ami_name "${SOURCE_AMI_NAME}" \
        --arg cp_ami_name "${CP_AMI_NAME}" \
        '{source_ami_id: $source_ami_id, source_ami_name: $source_ami_name, ami_name: $ami_name}'

error:

An error occurred (ValidationException) when calling the GetParameter operation: Parameter name: can't be prefixed with "ssm" (case-insensitive). If formed as a path, it can consist of sub-paths divided by slash symbol; each sub-path can be formed as a mix of letters, numbers and the following 3 symbols .-_

how i am running the above script

% ./build-versions.sh

An error occurred (ValidationException) when calling the GetParameter operation: Parameter name: can't be prefixed with "ssm" (case-insensitive). If formed as a path, it can consist of sub-paths divided by slash symbol; each sub-path can be formed as a mix of letters, numbers and the following 3 symbols .-_

答案1

得分: 0

请注意

```sh
aws ssm get-parameter \
  --name /aws/service/eks/optimized-ami/v1.23/amazon-linux-2/recommended/image_id \
  --region us-west-2

给我报错(ParameterNotFound)。我需要使用“1.23”而不是“v1.23”来获取有效的响应,即

aws ssm get-parameter \
  --name /aws/service/eks/optimized-ami/1.23/amazon-linux-2/recommended/image_id \
  --region us-west-2

下面我假设您还将使用“1.23”。


在这种情况下,在运行脚本之前设置VERSION=1.23是没有用的。在您的脚本中,VERSION=$1表示它将VERSION设置为脚本的第一个参数。因此,您应该运行

./build-versions.sh 1.23

而不是

VERSION=1.23
./build-versions.sh

如果您真的想在脚本之外设置它,那么您需要使用export VERSION=1.23进行设置,并删除VERSION=$1行。


<details>
<summary>英文:</summary>

Note that 

```sh
aws ssm get-parameter \
  --name /aws/service/eks/optimized-ami/v1.23/amazon-linux-2/recommended/image_id \
  --region us-west-2

Gives me error (ParameterNotFound). I need to use "1.23" instead of "v1.23" to get a valid response, namely

aws ssm get-parameter \
  --name /aws/service/eks/optimized-ami/1.23/amazon-linux-2/recommended/image_id \
  --region us-west-2

Below I assume you will also use "1.23".


Setting VERSION=1.23 before running the script is not useful in this case. In your script, VERSION=$1, which means it sets VERSION to the first argument of the script. Hence, you should run

./build-versions.sh 1.23

Instead of

VERSION=1.23
./build-versions.sh

If you really want to set it outside of your script, then you need to set it with export VERSION=1.23, and remove the VERSION=$1 line.

huangapple
  • 本文由 发表于 2023年5月11日 08:49:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76223451.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定