Docker 如果存在DynamoDB,请删除它

Docker 如果存在DynamoDB,请删除它,docker,makefile,amazon-dynamodb,Docker,Makefile,Amazon Dynamodb,我正在尝试使用docker在本地安装dynamodb。我希望通过使用makefile来控制初始化。这是我正在使用的makefile TABLE_NAME="users" create_db: @aws dynamodb --endpoint-url http://localhost:8042 create-table \ --table-name $(TABLE_NAME) \ --attribute-definitions \ AttributeNam

我正在尝试使用docker在本地安装dynamodb。我希望通过使用makefile来控制初始化。这是我正在使用的makefile

TABLE_NAME="users"

create_db:
    @aws dynamodb --endpoint-url http://localhost:8042 create-table \
    --table-name $(TABLE_NAME) \
    --attribute-definitions \
        AttributeName=userID,AttributeType=N \
    --key-schema \
        AttributeName=userID,KeyType=HASH \
    --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 >> /dev/null;

drop_db: check_db
    check_db; if [test $$? -eq 1] then \
        @aws dynamodb --endpoint-url http://localhost:8042 delete-table --table-name $(TABLE_NAME); \
    fi

check_db:
    -@aws dynamodb --endpoint-url http://localhost:8042 describe-table --table-name $(TABLE_NAME);
AWS不提供像MYSQL这样的DROP IF EXISTS功能,所以我尝试使用descripe表的输出来检查表的存在。但是,得到以下错误

check_db; if [test $? -eq 1] then \
        @aws dynamodb --endpoint-url http://localhost:8042 delete-table --table-name "requests"; \
    fi
/bin/sh: -c: line 0: syntax error near unexpected token `fi'
/bin/sh: -c: line 0: `check_db; if [test $? -eq 1] then     @aws dynamodb --endpoint-url http://localhost:8042 delete-table --table-name "requests"; fi'
make: *** [drop_db] Error 2
我是makefile新手,不知道如何解决这个错误。上面的makefile中有什么错误?还有什么更好的方法来检查dynamo表的存在吗?这不是Makefile问题,而是shell脚本中的语法错误。基本上你需要一个分号

您还需要决定使用[或测试],因为当前语法也不正确

$ false; if [test $? -eq 1]; then echo foo; fi

Command '[test' not found, did you mean:

...
工作版本:

$ false; if [ $? -eq 1 ]; then echo foo; fi
foo

我只是做了这个变通方法来模拟dynamoDB的DROP IF EXISTS功能

drop_db: check_db
    @if grep -q -i "active" a.out ; then \
        aws dynamodb --endpoint-url http://localhost:8042 delete-table --table-name $(TABLE_NAME) >> /dev/null; \
        rm a.out; \
    fi

check_db:
    @aws dynamodb --endpoint-url http://localhost:8042 describe-table --table-name $(TABLE_NAME) --output text &> a.out;
drop_db: check_db
    @if grep -q -i "active" a.out ; then \
        aws dynamodb --endpoint-url http://localhost:8042 delete-table --table-name $(TABLE_NAME) >> /dev/null; \
        rm a.out; \
    fi

check_db:
    @aws dynamodb --endpoint-url http://localhost:8042 describe-table --table-name $(TABLE_NAME) --output text &> a.out;