-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.ts
116 lines (112 loc) · 3.02 KB
/
serverless.ts
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import * as dotenv from 'dotenv';
dotenv.config();
import type { AWS } from '@serverless/typescript';
import { region, stage } from '@config/aws';
import { bedrockAgentId, bedrockActionGroupId, bedrockAgentAliasId } from '@config/env';
import api from '@functions/api';
import question from '@functions/question';
const serverlessConfiguration: AWS = {
service: 'm2m-ai',
frameworkVersion: '3',
plugins: ['serverless-esbuild'],
provider: {
region,
stage,
name: 'aws',
runtime: 'nodejs20.x',
timeout: 29,
apiGateway: {
minimumCompressionSize: 1024,
shouldStartNameWithService: true,
},
environment: {
BEDROCK_AGENT_ID: bedrockAgentId,
BEDROCK_ACTION_GROUP_ID: bedrockActionGroupId,
BEDROCK_AGENT_ALIAS_ID: bedrockAgentAliasId,
TABLE_ANSWERS: { Ref: 'TableAnswers' },
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
NODE_OPTIONS: '--enable-source-maps --stack-trace-limit=1000',
},
iamRoleStatements: [
{
Effect: 'Allow',
Action: ['bedrock:InvokeAgent'],
Resource: [
{
'Fn::Join': [
'',
[
'arn:aws:bedrock:',
{ Ref: 'AWS::Region' },
':',
{ Ref: 'AWS::AccountId' },
':agent-alias/',
bedrockAgentId,
'/',
bedrockAgentAliasId,
],
],
},
],
},
{
Effect: 'Allow',
Action: ['dynamodb:PutItem', 'dynamodb:GetItem'],
Resource: [{ 'Fn::GetAtt': ['TableAnswers', 'Arn'] }],
},
],
},
functions: { api, question },
resources: {
Resources: {
// Allow Bedrock to call the agent API Lambda
InvokePermission: {
Type: 'AWS::Lambda::Permission',
Properties: {
Action: 'lambda:InvokeFunction',
FunctionName: { 'Fn::GetAtt': ['ApiLambdaFunction', 'Arn'] },
Principal: 'bedrock.amazonaws.com',
SourceArn: {
'Fn::Join': [
'',
['arn:aws:bedrock:', { Ref: 'AWS::Region' }, ':', { Ref: 'AWS::AccountId' }, ':agent/', bedrockAgentId],
],
},
},
},
// DynamoDB table to store agent answers
TableAnswers: {
Type: 'AWS::DynamoDB::Table',
Properties: {
TableName: '${self:service}-answers',
AttributeDefinitions: [
{
AttributeName: 'id',
AttributeType: 'S',
},
],
KeySchema: [
{
AttributeName: 'id',
KeyType: 'HASH',
},
],
BillingMode: 'PAY_PER_REQUEST',
},
},
},
},
package: { individually: true },
custom: {
esbuild: {
bundle: true,
minify: false,
sourcemap: true,
target: 'node20',
define: { 'require.resolve': undefined },
platform: 'node',
concurrency: 10,
},
},
};
module.exports = serverlessConfiguration;