Skip to content

Commit

Permalink
Use unique app+project configuration for sample apps
Browse files Browse the repository at this point in the history
  • Loading branch information
gordon-klotho committed Aug 21, 2024
1 parent 1ea5695 commit 4660cd5
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 46 deletions.
6 changes: 2 additions & 4 deletions pkg/k2/language_host/python/samples/fastapi_postgres/infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@

# Create the Application instance
app = klotho.Application(
"my-app",
project=os.getenv("PROJECT_NAME", "my-project"), # Default to 'my-project' or the environment variable value
environment=os.getenv("KLOTHO_ENVIRONMENT", "default"), # Default to 'default' or the environment variable value
default_region=os.getenv("AWS_REGION", "us-east-1"), # Default to 'us-east-1' or the environment variable value
"app",
project=os.getenv("PROJECT_NAME", "fastapi_postgres"),
)

# Generate an absolute path to the directory containing the infra.py file /Dockerfile
Expand Down
11 changes: 2 additions & 9 deletions pkg/k2/language_host/python/samples/func/infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@

# Create the Application instance
app = klotho.Application(
"my-app",
project=os.getenv(
"PROJECT_NAME", "my-project"
), # Default to 'my-project' or the environment variable value
environment=os.getenv("KLOTHO_ENVIRONMENT", "default"),
# Default to 'default' or the environment variable value
default_region=os.getenv(
"AWS_REGION", "us-west-2"
), # Default to 'us-east-1' or the environment variable value
"app",
project=os.getenv("PROJECT_NAME", "func"),
)

dir = Path(__file__).parent.absolute()
Expand Down
8 changes: 3 additions & 5 deletions pkg/k2/language_host/python/samples/func_dynamo/infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

# Create the Application instance
app = klotho.Application(
"my-dynamo-app",
project=os.getenv("PROJECT_NAME", "my-project"),
environment=os.getenv("KLOTHO_ENVIRONMENT", "default"),
default_region=os.getenv("AWS_REGION", "us-west-2"),
"app",
project=os.getenv("PROJECT_NAME", "func_dynamo"),
)

dir = Path(__file__).parent.absolute()
Expand Down Expand Up @@ -39,4 +37,4 @@
code=str(dir),
)

my_function.bind(dynamodb)
my_function.bind(dynamodb)
20 changes: 18 additions & 2 deletions pkg/k2/language_host/python/samples/starter/infra-api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import infra
import os
from pathlib import Path

import klotho
import klotho.aws as aws

app = klotho.Application(
"api",
project=os.getenv("PROJECT_NAME", "starter1"),
)

dir = Path(__file__).parent.absolute()

container = aws.Container(
"my-container",
dockerfile=str(dir / "Dockerfile"),
context=str(dir),
)

api = aws.Api("my-api")
api.route_to("/", infra.container)
api.route_to("/", container)
14 changes: 2 additions & 12 deletions pkg/k2/language_host/python/samples/starter/infra-binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,13 @@
import klotho
import klotho.aws as aws

# Create the Application instance
app = klotho.Application(
"binding-app",
project=os.getenv(
"PROJECT_NAME", "my-project"
), # Default to 'my-project' or the environment variable value
environment=os.getenv("KLOTHO_ENVIRONMENT", "default"),
# Default to 'default' or the environment variable value
default_region=os.getenv(
"AWS_REGION", "us-west-2"
), # Default to 'us-east-1' or the environment variable value
"my-app",
project=os.getenv("PROJECT_NAME", "starter.binding"),
)

# Create a Bucket resource
bucket = aws.Bucket("my-bucket", force_destroy=True)

# Create a Container resource with a binding to the Bucket resource
container = aws.Container(
"my-container", dockerfile="Dockerfile", bindings=[bucket.use_read_only()]
)
8 changes: 3 additions & 5 deletions pkg/k2/language_host/python/samples/starter/infra-dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

# Create the Application instance
app = klotho.Application(
"my-dynamo-app",
project=os.getenv("PROJECT_NAME", "my-project"),
environment=os.getenv("KLOTHO_ENVIRONMENT", "default"),
default_region=os.getenv("AWS_REGION", "us-west-2"),
"dynamodb",
project=os.getenv("PROJECT_NAME", "starter"),
)

dir = Path(__file__).parent.absolute()

dynamodb = aws.DynamoDB("my-dynamodb", attributes=[{"Name": "id", "Type": "S"}], hash_key="id")
dynamodb = aws.DynamoDB("my-dynamodb", attributes=[{"Name": "id", "Type": "S"}], hash_key="id")
11 changes: 2 additions & 9 deletions pkg/k2/language_host/python/samples/starter/infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@

# Create the Application instance
app = klotho.Application(
"my-app",
project=os.getenv(
"PROJECT_NAME", "my-project"
), # Default to 'my-project' or the environment variable value
environment=os.getenv("KLOTHO_ENVIRONMENT", "default"),
# Default to 'default' or the environment variable value
default_region=os.getenv(
"AWS_REGION", "us-west-2"
), # Default to 'us-east-1' or the environment variable value
"basic",
project=os.getenv("PROJECT_NAME", "starter"),
)

dir = Path(__file__).parent.absolute()
Expand Down

0 comments on commit 4660cd5

Please sign in to comment.