gpt4 book ai didi

java - 在 Ubuntu WSL 中运行 bash 脚本时出现不一致的 S3 参数验证错误

转载 作者:行者123 更新时间:2023-12-04 18:39:00 25 4
gpt4 key购买 nike

我正在按照此处的说明试用 AWS Lambda:https://github.com/awsdocs/aws-lambda-developer-guide/tree/main/sample-apps/java-basic .
部分设置说明需要运行此脚本 (2-deploy.sh):

#!/bin/bash
set -eo pipefail
ARTIFACT_BUCKET=$(cat bucket-name.txt)
TEMPLATE=template.yml
if [ $1 ]
then
if [ $1 = mvn ]
then
TEMPLATE=template-mvn.yml
mvn package
fi
else
gradle build -i
fi

echo $TEMPLATE #debug
echo $ARTIFACT_BUCKET #debug
aws cloudformation package --template-file $TEMPLATE --s3-bucket $ARTIFACT_BUCKET --output-template-file out.yml
aws cloudformation deploy --template-file out.yml --stack-name java-basic --capabilities CAPABILITY_NAMED_IAM
当我在 WSL 中运行脚本时,出现参数验证错误:
$ ./2-deploy.sh mvn
... # Maven output

template-mvn.yml
lambda-artifacts-<alphanumeric string>
Unable to upload artifact target/java-basic-1.0-SNAPSHOT.jar referenced by CodeUri parameter of function resource.
Parameter validation failed: "
": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$" or be an ARN matching the regex "^arn:(aws).*:(s3|s3-object-lambda):[a-z\-0-9]+:[0-9]{12}:accesspoint[/:][a-zA-Z0-9\-]{1,63}$|^arn:(aws).*:s3-outposts:[a-z\-0-9]+:[0-9]{12}:outpost[/:][a-zA-Z0-9\-]{1,63}[/:]accesspoint[/:][a-zA-Z0-9\-]{1,63}$"
但是,当我使用调试输出手动运行文件的最后两行时,它可以正常工作:
adam@DESKTOP-ON98ECK:/mnt/c/Users/Ben/IdeaProjects/LakeStockingAlerter/sample-apps/java-basic$ aws cloudformation package --template-file template-mvn.yml --s3-bucket lambda-artifacts-<alphanumeric string>--output-template-file out.yml         
Uploading to ... 260754 / 260754.0 (100.00%)
Successfully packaged artifacts and wrote output template to file out.yml.
Execute the following command to deploy the packaged template
aws cloudformation deploy --template-file /mnt/c/Users/Ben/IdeaProjects/LakeStockingAlerter/sample-apps/java-basic/out.yml --stack-name <YOUR STACK NAME>
adam@DESKTOP-ON98ECK:/mnt/c/Users/Ben/IdeaProjects/LakeStockingAlerter/sample-apps/java-basic$ aws cloudformation deploy --template-file out.yml --stack-name java-basic --capabilities CAPABILITY_NAMED_IAM

Waiting for changeset to be created...
Waiting for stack create/update to complete
Successfully created/updated stack - java-basic
为什么在作为 bash 脚本运行时会失败?存储在变量中的字符都不是 bash 特殊的,所以我看不出变量替换有问题。该脚本还使用 Unix 风格的行尾。

最佳答案

根据评论。
问题是 bucket-name.txt文件包含 额外行 .随后$ARTIFACT_BUCKET包含换行符,导致错误。

关于java - 在 Ubuntu WSL 中运行 bash 脚本时出现不一致的 S3 参数验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67444939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com