Skip to content

Commit 6bde101

Browse files
committed
Added CloudFront for Fargate Service, with other fixes
1 parent 065dbd8 commit 6bde101

File tree

12 files changed

+18130
-18381
lines changed

12 files changed

+18130
-18381
lines changed

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,20 @@ cdk deploy --parameters SesBankEmail={email} --parameters SesCustomerEmail={emai
7474

7575
Example usage:
7676
```
77-
cdk deploy --parameters SesBankEmail=owner@anybank.com --parameters SesCustomerEmail=anup.ravi@test.com --parameters LLMImageTag=20240307_111334
77+
cdk deploy --parameters SesBankEmail=owner@anybank.com --parameters SesCustomerEmail=anup@test.com --parameters LLMImageTag=20240307_123456
7878
```
7979

8080
* Once your deployment is complete:
8181
* An email will be sent to the `SesBankEmail` and `SesCustomerEmail` you supplied to verify the new SES identities created. Please make sure to click the verification link provided in the email.
82-
* Visit the ECS Cluster created by the stack, open the running service and visit its task. The public IP address is your LLM endpoints.
83-
* Go to the Console and search for Elastic Container Service (ECS). Click on the cluster that was created and choose the task that is currently running. In the Configuration section for that task, you will find the Public IP address which is going to be your LLM endpoint (will be used in the next step).
84-
82+
* Copy the `CloudFrontDomainName` outputted by the CloudFormation Stack
8583

8684
> Note: If the CloudFormation Stack gets stuck on waiting for the completion of the LLMDeployment, it is possible that your ECS task has failed. This may be because the architecture of the machine you built the image on does not match what we have configured to be used in our project (ARM64). In that case, manually update the architecture the ECS Task Definition utilises (to possibly use X86 instead).
8785
8886
### Deploy the Demo Application to AWS Account
8987

9088
To deploy the demo application to your AWS account, follow the instructions below:
9189

92-
* Copy the LLM endpoint from the previous step. Update the `LLM_API_ENDPOINT` constant in `App.js` within `./penny-ui/src/`
90+
* Replace the value of `LLM_API_ENDPOINT` constant in `App.js` within `./penny-ui/src/` with `CloudFrontDomainName` outputted by the CloudFormation Stack.
9391
* Navigate to `./penny-ui`
9492
* Run the below commands to deploy the application amplify:
9593
```
@@ -98,7 +96,6 @@ amplify init
9896
amplify add hosting
9997
amplify publish
10098
```
101-
> Note: In chrome or some other browsers, you may not receive any response from the agent for very long. This is due to a Mixed Content error in the console as the ECS public endpoint is in http while the react app is deployed to https. To solve this in Chrome, press of the icon near the URL > Site settings > Insecure content > Allow
10299

103100
* Visit the outputted domain where your application has been deployed. Congratulations you can not start talking to the digital assistant!
104101

api/llm/app/penny/tools.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def setup_knowledge_base():
3030
"top_k": 250,
3131
"top_p": 0.999,
3232
"stop_sequences": ["\\n\\nHuman:", "\\n\\System:"],
33-
"anthropic_version": "bedrock-2023-05-31"
3433
}
3534
)
3635

@@ -71,7 +70,7 @@ def _run(self, query):
7170

7271
url = API_ENDPOINT + '/account'
7372
params = {'email': email.lower()}
74-
r = requests.get(url = url, params = params)
73+
r = requests.get(url = url, params = params, timeout=300)
7574

7675
print(r.json())
7776
if r.json()["statusCode"] != 200:
@@ -102,7 +101,7 @@ def _run(self, input=""):
102101
'file_name': file_name,
103102
'required_field_values': required_field_values
104103
}
105-
r = requests.post(url=url, json=body)
104+
r = requests.post(url=url, json=body, timeout=300)
106105

107106
print(r.json())
108107
if r.json()["statusCode"] != 200:
@@ -132,7 +131,7 @@ def _run(self, input=""):
132131
'id_file_name': id_file_name,
133132
'selfie_file_name': selfie_file_name
134133
}
135-
r = requests.post(url=url, json=body)
134+
r = requests.post(url=url, json=body, timeout=300)
136135

137136
if r.json()["statusCode"] != 200:
138137
return "Respond that our onboarding service is currently unavailable and to try again later."
@@ -175,7 +174,7 @@ def _run(self, input=""):
175174
'selfie_file_name': selfie_file_name
176175
}
177176
print(body)
178-
r = requests.post(url=url, json=body)
177+
r = requests.post(url=url, json=body, timeout=300)
179178
print(r)
180179

181180
if r.status_code != 200:

api/llm/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
fastapi==0.109.1
22
uvicorn==0.24.0.post1
33
pydantic==2.5.2
4-
langchain==0.1.12
4+
langchain==0.2.16
55
langchain-community==0.2.5
6-
torch==2.1.1
7-
torchvision==0.16.1
6+
torch==2.4.1
7+
torchvision==0.19.1
88
sentence-transformers==2.2.2
99
faiss-cpu==1.7.4
1010
email-validator==2.1.0

infra/cdk.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
4545
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
4646
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
47-
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
4847
"@aws-cdk/aws-redshift:columnId": true,
4948
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
5049
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,

infra/lib/infra-stack.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import * as ec2 from "aws-cdk-lib/aws-ec2";
1212
import * as kendra from "aws-cdk-lib/aws-kendra";
1313
import * as ses from "aws-cdk-lib/aws-ses";
1414
import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment';
15+
import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';
16+
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
17+
import * as origins from 'aws-cdk-lib/aws-cloudfront-origins';
18+
1519

1620
export class PennyInfraStack extends cdk.Stack {
1721
private customerTable: dynamodb.Table
@@ -394,5 +398,53 @@ export class PennyInfraStack extends cdk.Stack {
394398
securityGroups: [sg],
395399
serviceName: 'LLMFargateService'
396400
})
401+
402+
const lb = new elbv2.ApplicationLoadBalancer(this, 'PennyALB', {
403+
vpc: vpc,
404+
internetFacing: true,
405+
})
406+
407+
const httpListener = lb.addListener('PennyHttpListener', {
408+
port: 80,
409+
open: true,
410+
})
411+
412+
httpListener.addTargets('PennyECS', {
413+
port: 80,
414+
targets: [this.llmService],
415+
healthCheck: {
416+
path: '/',
417+
interval: cdk.Duration.seconds(60),
418+
},
419+
})
420+
421+
const corsHeadersPolicy = new cloudfront.ResponseHeadersPolicy(this, 'CorsHeadersPolicy', {
422+
responseHeadersPolicyName: 'CorsHeadersPolicy',
423+
corsBehavior: {
424+
accessControlAllowOrigins: ['*'],
425+
accessControlAllowMethods: ['GET', 'HEAD', 'OPTIONS', 'PUT', 'POST', 'PATCH', 'DELETE'],
426+
accessControlAllowHeaders: ['*'],
427+
accessControlAllowCredentials: false,
428+
originOverride: true,
429+
},
430+
});
431+
432+
const distribution = new cloudfront.Distribution(this, 'PennyDistribution', {
433+
defaultBehavior: {
434+
origin: new origins.HttpOrigin(lb.loadBalancerDnsName, {
435+
protocolPolicy: cloudfront.OriginProtocolPolicy.HTTP_ONLY,
436+
}),
437+
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
438+
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
439+
cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
440+
originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER,
441+
responseHeadersPolicy: corsHeadersPolicy,
442+
},
443+
});
444+
445+
new cdk.CfnOutput(this, 'CloudFrontDomainName', {
446+
value: distribution.distributionDomainName,
447+
});
448+
397449
}
398450
}

infra/package-lock.json

Lines changed: 9 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@
1111
"cdk": "cdk"
1212
},
1313
"devDependencies": {
14-
"@types/jest": "^29.5.5",
1514
"@types/node": "20.7.1",
16-
"jest": "^29.7.0",
17-
"ts-jest": "^29.1.1",
15+
"jest": "29.7.0",
16+
"ts-jest": "29.1.1",
1817
"aws-cdk": "2.101.1",
19-
"ts-node": "^10.9.1",
20-
"typescript": "~5.2.2"
18+
"ts-node": "10.9.1",
19+
"typescript": "5.2.2"
2120
},
2221
"dependencies": {
2322
"aws-cdk-lib": "2.101.1",
24-
"constructs": "^10.0.0",
25-
"source-map-support": "^0.5.21"
23+
"constructs": "10.0.0",
24+
"source-map-support": "0.5.21"
2625
}
2726
}

penny-ui/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ amplifytools.xcconfig
4343
.secret-*
4444
**.sample
4545
#amplify-do-not-edit-end
46+
47+
48+
/amplify
49+

0 commit comments

Comments
 (0)