1

I'm using localstack and awslocal to run the local AWS services inside a docker container.

Localstack is configured with a docker-compose.yml file.

Tests are written using Jest and AWS Node JS sdk for DynamoDB.

'use strict';
const { dbClient, db } = require('../../adapters/dynamodb');

const dbSchema = {
    TableName: 'DUMMY',
    KeySchema: [
        {
            AttributeName: 'dummyId',
            KeyType: 'HASH',
        },
    ],
    AttributeDefinitions: [
        {
            AttributeName: 'dummyId',
            AttributeType: 'S',
        },
    ],
    ProvisionedThroughput: {
        ReadCapacityUnits: 100,
        WriteCapacityUnits: 100,
    },
};

it('create DUMMY table', async () => {
    const { TableNames } = await db.listTables().promise();
    if (!TableNames.includes('DUMMY')) {
        const { TableDescription } = await db.createTable(dbSchema).promise();
        expect(TableDescription.TableName).toEqual('DUMMY');
    }
});
it('write/read to DUMMY table', async () => {
    await dbClient
        .put({
            TableName: 'DUMMY',
            Item: {
                dummyId: '123456',
                selectedIds: ['1', '2', '3'],
            },
        })
        .promise();

    const { Item } = await dbClient
        .get({
            TableName: 'DUMMY',
            Key: {
                dummyId: '123456',
            },
        })
        .promise();

    expect(Item.dummyId).toEqual('123456');
    expect(Item.selectedIds).toEqual(['1', '2', '3']);
});
it('delete DUMMY table', async () => {
    const { TableNames } = await db.listTables().promise();
    if (TableNames.includes('DUMMY')) {
        const result = await db.deleteTable({ TableName: 'DUMMY' }).promise();
        expect(result.TableDescription.TableName).toEqual('DUMMY');
    }
}, 25000);

Jest fails on the last test and dymanodb sdk throws the mentioned exception:

Jest fail

I tried using the awslocal cli to replicate this issue outside of jest and the same thing happens (used official aws docs for cli command examples):

awslocal dynamodb create-table --table-name MusicCollection --attribute-definitions AttributeName=Artist,AttributeType=S AttributeName=SongTitle,AttributeType=S --key-schema AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1 -> works!

awslocal dynamodb list-tables -> works! Logs out the list of existing tables: {"TableNames": ["MusicCollection"]}

awslocal dynamodb delete-table --table-name MusicCollection

...and I get the same exception: An error occurred (ResourceNotFoundException) when calling the DeleteTable operation: Cannot do operations on a non-existent table

And now the best part. Even though the exception is thrown, the table gets deleted: enter image description here enter image description here

Honestly, it's hard to come up with an explanation here, but I feel that there is something simple that I'm missing! Any help is appreciated <3

UPDATE: It's not 100% confirmed yet, but in DynamoDB docs only the deleteItem is said to be idempotent, but not deleteTable which means that this could be the issue here.

4

0 回答 0