localstack / localstack/aws-cdk-local

DatabaseCluster.clusterEndpoint.hostname does not respect LOCALSTACK_HOSTNAME

Open
#73 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

awaiting-response invalid
Dominant language
JavaScript
Stars
305
Forks
18
PR merge metrics
No merged PRs in 30d

Description

When deploying my RDS stack I have it put it's hostname into an SSM Parameter to be used by Lambda functions later. This doesn't seem to work when configuring `LOCALSTACK_HOSTNAME`, `HOSTNAME` and `HOSTNAME_EXTERNAL`.

Given the following `docker-compose.yaml` and cdk files

```yaml
version: "3.5"
services:
localstack:
container_name: "localstack"
image: localstack/localstack:latest
network_mode: bridge
ports:
- "80:80"
- "443:443"
- "4566:4566"
- "4510-4559:4510-4559" # external services port range
- "127.0.0.1:53:53" # DNS config (only required for Pro)
- "127.0.0.1:53:53/udp" # DNS config (only required for Pro)
- "4571:4571"
environment:
- SERVICES=sqs, lambda, apigateway, s3, sts, ssm, cloudformation, ecr, kms, iam, rds
- LOCALSTACK_HOSTNAME=172.26.0.1
- HOSTNAME=172.26.0.1
- HOSTNAME_EXTERNAL=172.26.0.1
- DOCKER_HOST=unix:///var/run/docker.sock
- DEFAULT_REGION=eu-west-2
- TEST_AWS_ACCOUNT_ID=000000000000
volumes:
- "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
```

```ts
import { App, Stack } from "aws-cdk-lib";
import { Construct } from "constructs";
import { StringParameter } from "aws-cdk-lib/aws-ssm";
import {
AuroraPostgresEngineVersion,
DatabaseCluster,
DatabaseClusterEngine,
} from "aws-cdk-lib/aws-rds";
import { Vpc } from "aws-cdk-lib/aws-ec2";

class TestStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);

new DbConstruct(this, "consumer");
}
}

class DbConstruct extends Construct {
constructor(scope: Construct, id: string) {
super(scope, id);

const cluster = new DatabaseCluster(this, "DatabaseCluster", {
engine: DatabaseClusterEngine.auroraPostgres({
version: AuroraPostgresEngineVersion.VER_13_4,
}),
defaultDatabaseName: "database",
storageEncrypted: true,
instanceProps: {
vpc: new Vpc(this, "db-vpc"),
},
});

new StringParameter(this, `DatabaseEndpoint`, {
parameterName: "databaseEndpoint",
stringValue: cluster.clusterEndpoint.hostname,
});
}
}

const app = new App();

new TestStack(app, "stack");
```

I get the following results when querying by console

```
$ awslocal ssm get-parameter --name databaseEndpoint
{
"Parameter": {
"Name": "databaseEndpoint",
"Type": "String",
"Value": "localhost",
"Version": 1,
"LastModifiedDate": "2022-08-03T15:36:53.410000+01:00",
"ARN": "arn:aws:ssm:eu-west-2:000000000000:parameter/databaseEndpoint",
"DataType": "text"
}
}

$ awslocal rds describe-db-clusters
{
"DBClusters": [
{
"AllocatedStorage": 1,
"DatabaseName": "database",
"DBClusterIdentifier": "dbc-63393c9f",
"DBClusterParameterGroup": "default.aurora-postgresql13",
"DBSubnetGroup": "consumerDatabaseClusterSubnets68C9D7B3-baf5d77a",
"Status": "error",
"Endpoint": "172.26.0.1:4511",
"MultiAZ": false,
"Engine": "aurora-postgresql",
"EngineVersion": "13.4",
"Port": 4511,
"MasterUsername": "postgres",
"StorageEncrypted": false,
"DBClusterArn": "arn:aws:rds:eu-west-2:000000000000:cluster:dbc-63393c9f",
"IAMDatabaseAuthenticationEnabled": false,
"CopyTagsToSnapshot": true
}
]
}

```

Of note here is that the endpoint from `describe-db-clusters` is `172.26.0.1:4511` whereas the value that gets stored in ssm is `localhost`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the docker-compose.yaml environment settings and the CDK example using DatabaseCluster.clusterEndpoint.hostname, then trace how the endpoint is synthesized and exposed through the local AWS services. Compare the SSM value with the endpoint returned by rds describe-db-clusters. Done means the configured host is respected instead of being stored as localhost.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.