Skip to content

Commit ea3b1db

Browse files
authored
Changes for Terraform Setup (#60)
## Summary This makes DYNAMO_ENDPOINT and AWS_DEFAULT_REGION optional values instead of required. It also allows the app and frontend to be on different ip addresses, managed by kubernetes. ## Checklist - [ ] Added Unit Tests - [ ] Covered by existing CI - [ ] Integration tested - [ ] Documentation update <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced handling of allowed hosts and CORS settings for better integration with various services. - **Bug Fixes** - Improved flexibility in the initialization logic of the DynamoDbClient, allowing for optional environment variables without throwing immediate exceptions. - **Chores** - Updated environment variable declarations in the Dockerfile for standardized syntax. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent e9b6aaf commit ea3b1db

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

.github/image/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ RUN wget -O /etc/apk/keys/amazoncorretto.rsa.pub https://apk.corretto.aws/amazon
1212
RUN apk add --no-cache amazon-corretto-17
1313

1414
# java
15-
ENV JAVA_HOME /usr/lib/jvm/default-jvm
16-
ENV PATH $PATH:$JAVA_HOME/bin
15+
ENV JAVA_HOME=/usr/lib/jvm/default-jvm
16+
ENV PATH=$PATH:$JAVA_HOME/bin
1717

1818
# sbt for scala
1919
RUN curl -L "https://github.com/sbt/sbt/releases/download/v1.8.2/sbt-1.8.2.tgz" | tar -xz -C /usr/local

cloud_aws/src/main/scala/ai/chronon/integrations/aws/AwsApiImpl.scala

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,26 @@ import java.net.URI
1717
*/
1818
class AwsApiImpl(conf: Map[String, String]) extends Api(conf) {
1919
@transient lazy val ddbClient: DynamoDbClient = {
20-
val regionEnvVar =
21-
sys.env.getOrElse("AWS_DEFAULT_REGION", throw new IllegalArgumentException("Missing AWS_DEFAULT_REGION env var"))
22-
val dynamoEndpoint =
23-
sys.env.getOrElse("DYNAMO_ENDPOINT", throw new IllegalArgumentException("Missing DYNAMO_ENDPOINT env var"))
24-
25-
DynamoDbClient
20+
var builder = DynamoDbClient
2621
.builder()
27-
.region(Region.of(regionEnvVar))
28-
.endpointOverride(URI.create(dynamoEndpoint)) // TODO remove post docker
29-
.build()
22+
sys.env.get("AWS_DEFAULT_REGION").foreach { region =>
23+
try {
24+
builder = builder.region(Region.of(region))
25+
} catch {
26+
case e: IllegalArgumentException =>
27+
throw new IllegalArgumentException(s"Invalid AWS region format: $region", e)
28+
}
29+
}
30+
sys.env.get("DYNAMO_ENDPOINT").foreach { endpoint =>
31+
try {
32+
builder = builder.endpointOverride(URI.create(endpoint))
33+
} catch {
34+
case e: IllegalArgumentException =>
35+
throw new IllegalArgumentException(s"Invalid DynamoDB endpoint URI: $endpoint", e)
36+
}
37+
}
38+
builder.build()
39+
3040
}
3141

3242
override def genKvStore: KVStore = {

hub/conf/application.conf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ play.http.parser.maxDiskBuffer=10M
1111

1212
play.filters.hosts {
1313
# Allow requests to localhost:9000 and "app" for now
14-
allowed = ["localhost:9000", ".app"]
14+
allowed = ["localhost:9000", ".app", ${?APP_SERVICE_HOST}]
1515
}
1616

1717
# Add CORS filter
1818
play.filters.enabled += "play.filters.cors.CORSFilter"
1919

2020
# CORS configuration
2121
play.filters.cors {
22-
allowedOrigins = ["http://localhost:5173", "http://localhost:3000"]
22+
allowedOrigins = ["http://localhost:5173",
23+
"http://localhost:3000",
24+
"http://${?FRONTEND_SERVICE_HOST}:${?FRONTEND_SERVICE_PORT}",
25+
"https://${?FRONTEND_SERVICE_HOST}:${?FRONTEND_SERVICE_PORT}"]
2326
allowedHttpMethods = ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
2427
allowedHttpHeaders = ["Accept", "Content-Type"]
2528
}

0 commit comments

Comments
 (0)