Skip to content

Commit 7053316

Browse files
committed
chore: wip
1 parent ee61d7d commit 7053316

File tree

1 file changed

+14
-9
lines changed
  • storage/framework/.stacks/core/cloud/src/cloud

1 file changed

+14
-9
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,27 @@ export class AiStack {
2020
description: 'Layer with aws-sdk',
2121
})
2222

23-
// Defining the Node.js Lambda function
23+
const aiRole = new iam.Role(scope, 'AiRole', {
24+
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
25+
})
26+
27+
// Granting the Lambda permission to invoke the AI model
28+
aiRole.addToPolicy(
29+
new iam.PolicyStatement({
30+
actions: ['bedrock:InvokeModel'],
31+
resources: config.ai.models?.map(model => `arn:aws:bedrock:us-east-1:${props.env.account}:foundation-model/${model}`),
32+
effect: iam.Effect.ALLOW,
33+
}),
34+
)
35+
2436
const aiLambda = new lambda.Function(scope, 'LambdaFunction', {
2537
functionName: `${props.slug}-${props.appEnv}-ai`,
2638
description: 'Lambda function to invoke the AI model',
2739
runtime: lambda.Runtime.NODEJS_20_X,
2840
handler: 'index.handler',
2941
code: lambda.Code.fromAsset('src/cloud/lambda'), // path relative to the cloud root package dir
3042
layers: [awsSdkLayer],
43+
role: aiRole,
3144
})
3245

3346
const api = new lambda.FunctionUrl(scope, 'AiLambdaUrl', {
@@ -38,14 +51,6 @@ export class AiStack {
3851
},
3952
})
4053

41-
// Granting the Lambda permission to invoke the AI model
42-
aiLambda.role?.addToPrincipalPolicy(
43-
new iam.PolicyStatement({
44-
actions: ['bedrock:InvokeModel'],
45-
resources: config.ai.models?.map(model => `arn:aws:bedrock:us-east-1:${props.env.account}:foundation-model/${model}`),
46-
}),
47-
)
48-
4954
new Output(scope, 'AiApiUrl', {
5055
value: api.url,
5156
})

0 commit comments

Comments
 (0)