Skip to content

Commit c2a49c7

Browse files
committed
chore: wip
1 parent 3223d41 commit c2a49c7

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
aws_iam as iam,
66
aws_lambda as lambda,
77
} from 'aws-cdk-lib'
8+
import { HttpApi, HttpMethod } from 'aws-cdk-lib/aws-apigatewayv2'
9+
import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations'
810
import type { Construct } from 'constructs'
911
import { config } from '@stacksjs/config'
1012
import type { NestedCloudProps } from '../types'
@@ -23,8 +25,8 @@ export class AiStack {
2325

2426
const bedrockAccessPolicy = new iam.PolicyStatement({
2527
effect: iam.Effect.ALLOW,
26-
actions: ['bedrock:InvokeModel'], // See: https://docs.aws.amazon.com/ja_jp/service-authorization/latest/reference/list_amazonbedrock.html
27-
resources: ['*'],
28+
actions: ['bedrock:InvokeModel'],
29+
resources: config.ai.models?.map(model => `arn:aws:bedrock:us-east-1::foundation-model/${model}`),
2830
})
2931

3032
const bedrockAccessRole = new iam.Role(scope, 'BedrockAccessRole', {
@@ -36,14 +38,6 @@ export class AiStack {
3638

3739
bedrockAccessRole.addToPolicy(bedrockAccessPolicy)
3840

39-
// aiRole.addToPolicy(
40-
// new iam.PolicyStatement({
41-
// actions: ['bedrock:InvokeModel'],
42-
// resources: config.ai.models?.map(model => `arn:aws:bedrock:us-east-1:${props.env.account}:foundation-model/${model}`),
43-
// effect: iam.Effect.ALLOW,
44-
// }),
45-
// )
46-
4741
const aiLambda = new lambda.Function(scope, 'AiFunction', {
4842
functionName: `${props.slug}-${props.appEnv}-ai`,
4943
description: 'Lambda function to invoke the AI model',
@@ -55,16 +49,24 @@ export class AiStack {
5549
timeout: Duration.seconds(30),
5650
})
5751

58-
const api = new lambda.FunctionUrl(scope, 'AiLambdaUrl', {
59-
function: aiLambda,
60-
authType: lambda.FunctionUrlAuthType.NONE,
61-
cors: {
62-
allowedOrigins: ['*'],
63-
},
52+
const api = new HttpApi(scope, 'AiApi')
53+
54+
api.addRoutes({
55+
path: '/prompt',
56+
methods: [HttpMethod.POST],
57+
integration: new HttpLambdaIntegration('AiIntegration', aiLambda),
6458
})
6559

60+
// const api = new lambda.FunctionUrl(scope, 'AiLambdaUrl', {
61+
// function: aiLambda,
62+
// authType: lambda.FunctionUrlAuthType.NONE,
63+
// cors: {
64+
// allowedOrigins: ['*'],
65+
// },
66+
// })
67+
6668
new Output(scope, 'AiApiUrl', {
67-
value: api.url,
69+
value: api.apiEndpoint,
6870
})
6971
}
7072
}

storage/framework/.stacks/ide/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ alrighty
33
amazonses
44
amazonwebservices
55
antfu
6+
apigatewayv
67
applypatch
78
appsettings
89
arrayable

0 commit comments

Comments
 (0)