如何检查 shell 脚本中 s3 存储桶中的文件夹是否存在

how to check if a folder in s3 bucket exists or not in shell script

我有一个名为:bucket1 的存储桶。我必须检查是否存在与上个月相同的特定文件夹。

所以,例如我今天想 运行 来自 aws datapipeline 的脚本,首先它会使用 shellcommand activity.[=12 检查 s3 中上个月的文件夹是否存在=]

我正在使用这个,但它对所有人都是正确的cases.Can有人请帮忙吗?

#!/bin/bash

lastmonth='date -d "$(date +%Y-%m-1) -1 month" +%m'
newpath="s3://bucket1//2020/$lastmonth/"                     
echo "Path is : $newpath"

state='aws s3 ls $newpath'
if [ -z "$state" ]
then
     exit 1
else
    echo "Path exists"
    exit 0
fi
#!/bin/bash

lastmonth=`date -d "$(date +%Y-%m-1) -1 month" +%m`
newpath="s3://bucket1//2020/$lastmonth/"                     
echo "Path is : $newpath"

state=`aws s3 ls $newpath`
if [ -z "$state" ]
then
     exit 1
else
    echo "Path exists"
    exit 0
fi