LNI
LNI

Reputation: 3181

DynamoDB local behaving erratically

This is a very strange situation that's driving me nuts, and I would really appreciate some help here.

I am using CDK to define the DynamoDB table and associated indices. To test them locally, I installed cdklocal and DynamoDB local using localstack. When the computer (Mac running Ventura 13.1) is restarted, everything works as expected. Here is the script I use to bootstrap and start the stack (this is in a file called startStack.sh):

docker-compose up -d
echo "Waiting for 5 seconds"
sleep 5
cd test-app
cdklocal bootstrap
echo "Waiting for 5 seconds"
sleep 5
cdklocal deploy TestAppStack
#cdklocal deploy TestAppStack/ops-table
DYNAMO_ENDPOINT="http://localhost:4566/" dynamodb-admin &
open http://0.0.0.0:8001
cd ..

The test-app directory contains a local copy of the DynamoDB (and associated indices) definition. I do not encounter any errors running the cdklocal (or cdk) deploy commands so I am assuming that the CDK definition is not an issue.

The docker-compose looks like this:

version: "3.8"

services:
  localstack:
    container_name: AWS-DEVELOPMENT-WITH-LOCALSTACK
    image: localstack/localstack:latest
    network_mode: bridge
    ports:
      - "127.0.0.1:53:53"
      - "127.0.0.1:53:53/udp"
      - "127.0.0.1:443:443"
      - "127.0.0.1:4566:4566"
      - "127.0.0.1:4571:4571"
      - "127.0.0.1:${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}"
    environment:
      - DYNAMODB_SHARE_DB=1
      - DISABLE_CORS_CHECKS=1
      - SERVICES=s3,dynamodb,sns,sqs,firehose,kinesis,ses,sts,cloudformation
      - DEBUG=1
      - DATA_DIR=/tmp/localstack/data
      - PORT_WEB_UI=8080
      - LAMBDA_EXECUTOR=local
      - KINESIS_ERROR_PROBABILITY=1.0
      - DOCKER_HOST=unix:///var/run/docker.sock
      - HOST_TMP_FOLDER=./.localstack
    volumes:
      - './.localstack:/var/lib/localstack'
      - '/var/run/docker.sock:/var/run/docker.sock'

Everything works as expected when I first run the startStack.sh file - the dynamodb-admin window opens up correctly and other interfaces can interact with the local DynamoDB table. But after some time (and I have not been able to pinpoint the cause), all interactions with local DynamoDB start failing with the following error(s):

Bootstrapping environment aws://000000000000/us-west-2...
 ❌  Environment aws://000000000000/us-west-2 failed bootstrapping: UnknownEndpoint: Inaccessible host: `localhost' at port `4566'. This service may not be available in the `us-west-2' region.
    at Request.ENOTFOUND_ERROR (/usr/local/lib/node_modules/aws-sdk/lib/event_listeners.js:611:46)
    at Request.callListeners (/usr/local/lib/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/usr/local/lib/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/usr/local/lib/node_modules/aws-sdk/lib/request.js:686:14)
    at error2 (/usr/local/lib/node_modules/aws-sdk/lib/event_listeners.js:443:22)
    at ClientRequest.<anonymous> (/usr/local/lib/node_modules/aws-sdk/lib/http/node.js:99:9)
    at ClientRequest.emit (node:events:513:28)
    at ClientRequest.emit (node:domain:489:12)
    at Socket.socketErrorListener (node:_http_client:494:9)
    at Socket.emit (node:events:513:28) {
  code: 'UnknownEndpoint',
  region: 'us-west-2',
  hostname: 'localhost',
  retryable: true,
  originalError: [Error],
  time: 2023-01-15T06:46:40.614Z
}

Inaccessible host: `localhost' at port `4566'. This service may not be available in the `us-west-2' region.

The script hangs at the following message:

[16:52:01] Retrieved account ID 000000000000 from disk cache
[16:52:01] Assuming role 'arn:aws:iam::000000000000:role/cdk-hnb659fds-deploy-role-000000000000-us-west-2'.
[16:52:01] Assuming role failed: Inaccessible host: `localhost' at port `4566'. This service may not be available in the `us-west-2' region.
[16:52:01] Could not assume role in target account using current credentials Inaccessible host: `localhost' at port `4566'. This service may not be available in the `us-west-2' region. . Please make sure that this role exists in the account. If it doesn't exist, (re)-bootstrap the environment with the right '--trust', using the latest version of the CDK CLI.
current credentials could not be used to assume 'arn:aws:iam::000000000000:role/cdk-hnb659fds-deploy-role-000000000000-us-west-2', but are for the right account. Proceeding anyway.
[16:52:01] Waiting for stack CDKToolkit to finish creating or updating...

Restarting the computer fixes it, but it's not clear what causes the issue in the first place. Restarting Docker does not help either.

Any thoughts on what could be causing the problem and how I can avoid it?

Upvotes: 0

Views: 331

Answers (1)

Leeroy Hannigan
Leeroy Hannigan

Reputation: 19883

I'm adding this as an answer, although I do not have an affirmative answer I thought I would try to help.

I believe your port is being occupied and thus the process you are running is unable to obtain it resulting in error. Before running the job, check if the port is occupied:

sudo lsof -i :4566

Upvotes: 1

Related Questions