Skip to content

Commit b28f7e0

Browse files
committed
chore: wip
1 parent 9e3826a commit b28f7e0

File tree

4 files changed

+71
-61
lines changed

4 files changed

+71
-61
lines changed

storage/framework/core/buddy/src/commands/deploy.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,44 +54,42 @@ export function deploy(buddy: CLI) {
5454
console.log(`${italic('This may take a while...')}`)
5555
await new Promise(resolve => setTimeout(resolve, 2000))
5656
options.domain = domain
57-
}
5857

59-
// if the domain hasn't been added to the user's (AWS) cloud, we will add it for them
60-
// and then exit the process with prompts for the user to update their nameservers
61-
else {
62-
console.log('')
63-
log.info(` 👋 It appears to be your first ${italic(domain)} deployment.`)
64-
console.log('')
65-
log.info(italic('Let’s ensure it is all connected properly.'))
66-
log.info(italic('One moment...'))
67-
console.log('')
68-
69-
options.domain = domain
70-
const result = await addDomain({
71-
...options,
72-
deploy: true,
73-
startTime,
74-
})
58+
// now that we know the domain has been added to the users (AWS) cloud, we can deploy
59+
const result = await runAction(Action.Deploy, options)
7560

7661
if (result.isErr()) {
7762
await outro('While running the `buddy deploy`, there was an issue', { startTime, useSeconds: true }, result.error)
7863
process.exit(ExitCode.FatalError)
7964
}
8065

81-
await outro('Added your domain.', { startTime, useSeconds: true })
66+
await outro('Deployment succeeded.', { startTime, useSeconds: true })
67+
8268
process.exit(ExitCode.Success)
8369
}
8470

85-
// now that we know the domain has been added to the users (AWS) cloud, we can deploy
86-
const result = await runAction(Action.Deploy, options)
71+
// if the domain hasn't been added to the user's (AWS) cloud, we will add it for them
72+
// and then exit the process with prompts for the user to update their nameservers
73+
console.log('')
74+
log.info(` 👋 It appears to be your first ${italic(domain)} deployment.`)
75+
console.log('')
76+
log.info(italic('Let’s ensure it is all connected properly.'))
77+
log.info(italic('One moment...'))
78+
console.log('')
79+
80+
options.domain = domain
81+
const result = await addDomain({
82+
...options,
83+
deploy: true,
84+
startTime,
85+
})
8786

8887
if (result.isErr()) {
8988
await outro('While running the `buddy deploy`, there was an issue', { startTime, useSeconds: true }, result.error)
9089
process.exit(ExitCode.FatalError)
9190
}
9291

93-
await outro('Deployment succeeded.', { startTime, useSeconds: true })
94-
92+
await outro('Added your domain.', { startTime, useSeconds: true })
9593
process.exit(ExitCode.Success)
9694
})
9795

storage/framework/core/cloud/src/cloud/ai.ts

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export interface AiStackProps extends NestedCloudProps {
99
}
1010

1111
export class AiStack {
12+
askAiUrl: lambda.FunctionUrl
13+
1214
constructor(scope: Construct, props: AiStackProps) {
1315
// Define the Lambda Layer for aws-sdk
1416
const awsSdkLayer = new lambda.LayerVersion(scope, 'AwsSdkLayer', {
@@ -46,6 +48,14 @@ export class AiStack {
4648
timeout: Duration.seconds(30),
4749
})
4850

51+
this.askAiUrl = new lambda.FunctionUrl(scope, 'AskAiFunctionUrl', {
52+
function: askAi,
53+
authType: lambda.FunctionUrlAuthType.NONE,
54+
cors: {
55+
allowedOrigins: ['*'],
56+
},
57+
})
58+
4959
const summarizeAi = new lambda.Function(scope, 'AiFunction', {
5060
functionName: `${props.slug}-${props.appEnv}-ai-summarize`,
5161
description: 'Lambda function to summarize any given text',
@@ -57,51 +67,51 @@ export class AiStack {
5767
timeout: Duration.seconds(30),
5868
})
5969

60-
const api = new RestApi(scope, 'AiRestApi', {
61-
restApiName: `${props.slug}-${props.appEnv}-ai`,
62-
description: 'Stacks AI API',
63-
defaultCorsPreflightOptions: {
64-
allowOrigins: Cors.ALL_ORIGINS,
65-
allowMethods: Cors.ALL_METHODS,
70+
const summarizeAiUrl = new lambda.FunctionUrl(scope, 'SummarizeAiFunctionUrl', {
71+
function: summarizeAi,
72+
authType: lambda.FunctionUrlAuthType.NONE,
73+
cors: {
74+
allowedOrigins: ['*'],
6675
},
6776
})
6877

69-
const askResource = api.root.addResource('ask')
70-
const askIntegration = new LambdaIntegration(askAi)
71-
askResource.addMethod('POST', askIntegration, {
72-
operationName: 'Stacks AI Ask',
73-
authorizationType: AuthorizationType.NONE,
74-
})
78+
// const api = new RestApi(scope, 'AiRestApi', {
79+
// restApiName: `${props.slug}-${props.appEnv}-ai`,
80+
// description: 'Stacks AI API',
81+
// defaultCorsPreflightOptions: {
82+
// allowOrigins: Cors.ALL_ORIGINS,
83+
// allowMethods: Cors.ALL_METHODS,
84+
// },
85+
// })
7586

76-
// alias to ask
77-
const promptResource = api.root.addResource('prompt')
78-
const promptIntegration = new LambdaIntegration(askAi)
79-
promptResource.addMethod('POST', promptIntegration, {
80-
operationName: 'Stacks AI Ask',
81-
authorizationType: AuthorizationType.NONE,
82-
})
87+
// const askResource = api.root.addResource('ask')
88+
// const askIntegration = new LambdaIntegration(askAi)
89+
// askResource.addMethod('POST', askIntegration, {
90+
// operationName: 'Stacks AI Ask',
91+
// authorizationType: AuthorizationType.NONE,
92+
// })
8393

84-
const summarizeResource = api.root.addResource('summarize')
85-
const summarizeIntegration = new LambdaIntegration(summarizeAi)
86-
summarizeResource.addMethod('POST', summarizeIntegration, {
87-
operationName: 'Stacks AI Summarize',
88-
authorizationType: AuthorizationType.NONE,
89-
})
94+
// alias to ask
95+
// const promptResource = api.root.addResource('prompt')
96+
// const promptIntegration = new LambdaIntegration(askAi)
97+
// promptResource.addMethod('POST', promptIntegration, {
98+
// operationName: 'Stacks AI Ask',
99+
// authorizationType: AuthorizationType.NONE,
100+
// })
90101

91-
// const api = new lambda.FunctionUrl(scope, 'AiLambdaUrl', {
92-
// function: aiLambda,
93-
// authType: lambda.FunctionUrlAuthType.NONE,
94-
// cors: {
95-
// allowedOrigins: ['*'],
96-
// },
102+
// const summarizeResource = api.root.addResource('summarize')
103+
// const summarizeIntegration = new LambdaIntegration(summarizeAi)
104+
// summarizeResource.addMethod('POST', summarizeIntegration, {
105+
// operationName: 'Stacks AI Summarize',
106+
// authorizationType: AuthorizationType.NONE,
97107
// })
98108

99109
new Output(scope, 'AiVanityAskApiUrl', {
100-
value: `${api.url}ask`,
110+
value: this.askAiUrl.url,
101111
})
102112

103113
new Output(scope, 'AiVanitySummarizeApiUrl', {
104-
value: `${api.url}summarize`,
114+
value: summarizeAiUrl.url,
105115
})
106116

107117
new Output(scope, 'AiAskApiUrl', {

storage/framework/core/cloud/src/cloud/cdn.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface CdnStackProps extends NestedCloudProps {
1919
webServer: lambda.Function
2020
webServerUrl: lambda.FunctionUrl
2121
cliSetupUrl: lambda.FunctionUrl
22+
askAiUrl: lambda.FunctionUrl
2223
}
2324

2425
export class CdnStack {
@@ -241,12 +242,12 @@ export class CdnStack {
241242
}
242243
}
243244

244-
aiBehaviorOptions(scope: Construct): Record<string, cloudfront.BehaviorOptions> {
245-
// const url = new URL()
246-
245+
aiBehaviorOptions(scope: Construct, props: CdnStackProps): Record<string, cloudfront.BehaviorOptions> {
246+
const hostname = Fn.select(2, Fn.split('/', props.askAiUrl.url))
247247
return {
248248
'/ai/ask': {
249-
origin: new origins.HttpOrigin('9qp44a2b7e.execute-api.us-east-1.amazonaws.com', {
249+
// origin: new origins.HttpOrigin('9qp44a2b7e.execute-api.us-east-1.amazonaws.com', {
250+
origin: new origins.HttpOrigin(hostname, {
250251
originPath: '/ai',
251252
protocolPolicy: cloudfront.OriginProtocolPolicy.HTTPS_ONLY,
252253
}),
@@ -339,7 +340,7 @@ export class CdnStack {
339340

340341
if (this.shouldDeployAiEndpoints()) {
341342
behaviorOptions = {
342-
...this.aiBehaviorOptions(scope),
343+
...this.aiBehaviorOptions(scope, props),
343344
...behaviorOptions,
344345
}
345346
}

storage/framework/core/cloud/src/cloud/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class Cloud extends Stack {
7070
certificate: security.certificate,
7171
})
7272

73-
new AiStack(this, props)
73+
const ai = new AiStack(this, props)
7474

7575
const cli = new CliStack(this, props)
7676

@@ -85,6 +85,7 @@ export class Cloud extends Stack {
8585
webServer: api.apiServer,
8686
webServerUrl: api.apiServerUrl,
8787
cliSetupUrl: cli.cliSetupUrl,
88+
askAiUrl: ai.askAiUrl,
8889
})
8990

9091
new DeploymentStack(this, {

0 commit comments

Comments
 (0)