-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcdk.py
54 lines (46 loc) · 1.41 KB
/
cdk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
from pathlib import Path
from constructs import Construct
from aws_cdk import (
App,
Stack,
Environment,
Duration,
CfnOutput,
)
from aws_cdk.aws_lambda import (
DockerImageFunction,
DockerImageCode,
Architecture,
FunctionUrlAuthType,
)
my_environment = Environment(
account=os.environ["CDK_DEFAULT_ACCOUNT"], region=os.environ["CDK_DEFAULT_REGION"]
)
class CatDogClassifierFastAPIStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
# Create Lambda function
lambda_fn = DockerImageFunction(
self,
"CatDogClassifierFastAPI",
code=DockerImageCode.from_image_asset(
str(Path.cwd()), # Uses the Dockerfile in the current directory
file="Dockerfile",
),
architecture=Architecture.X86_64,
memory_size=8192, # 8GB memory
timeout=Duration.minutes(5),
)
# Add HTTPS URL
fn_url = lambda_fn.add_function_url(auth_type=FunctionUrlAuthType.NONE)
# Output the function URL
CfnOutput(
self,
"FunctionUrl",
value=fn_url.url,
description="URL for the Lambda function",
)
app = App()
CatDogClassifierFastAPIStack(app, "CatDogClassifierFastAPIStack", env=my_environment)
app.synth()