-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
144 lines (138 loc) · 5.29 KB
/
template.yaml
File metadata and controls
144 lines (138 loc) · 5.29 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
genbot
Uses generative AI to create image based on given prompt
# More info about Globals: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-template-anatomy-globals.html
Globals:
HttpApi:
AccessLogSettings:
DestinationArn: !GetAtt GenBotFunctionApiLogGroup.Arn
# Common Log Format (CLF) - https://httpd.apache.org/docs/current/logs.html#common
Format: $context.identity.sourceIp - - [$context.requestTime] "$context.httpMethod $context.routeKey $context.protocol" $context.status $context.responseLength $context.requestId $context.extendedRequestId
Tags:
Application: bots
Function:
Runtime: nodejs24.x
Tags:
Application: bots
Resources:
GenBotImagesBucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: case-consulting-mgmt-genbot-images
LifecycleConfiguration:
Rules:
- Id: Remove old images
ExpirationInDays: 183 # ~6 months
Status: Enabled
Tags:
- Key: Application
Value: bots
GenBotFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html
DependsOn:
- GenBotImagesBucket
- GenBotRetrieveFunctionUrl
Properties:
FunctionName: genbot
CodeUri: ./
Handler: generate.handler
Description: Uses generative AI to create image based on given prompt
Timeout: 30
MemorySize: 512
Environment:
Variables:
accountId: !Ref AWS::AccountId
companyId: '{{resolve:ssm:/Basecamp/CompanyID:1}}'
retrieveApi: !GetAtt GenBotRetrieveFunctionUrl.FunctionUrl
Policies:
- Statement:
- Sid: InvokeFoundationModel
Effect: Allow
Action:
- bedrock:InvokeModel
Resource:
- !Sub arn:aws:bedrock:*::foundation-model/stability.stable-image-style-guide-v1:0
- !Sub arn:aws:bedrock:${AWS::Region}:*:inference-profile/us.stability.stable-image-style-guide-v1:0
- Statement:
- Sid: AllowImageBucketObjectPut
Effect: Allow
Action:
- s3:PutObject
Resource: 'arn:aws:s3:::case-consulting-mgmt-genbot-images/*'
Events:
GenBot:
Type: HttpApi # More info about HTTP API Event Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-httpapi.html
Properties:
Path: /
Method: post
GenBotFunctionLogGroup:
Type: AWS::Logs::LogGroup
DependsOn:
- GenBotFunction
Properties:
LogGroupName: !Sub /aws/lambda/${GenBotFunction}
RetentionInDays: 30
GenBotFunctionApiLogGroup:
Type: AWS::Logs::LogGroup
DependsOn:
- GenBotFunction
Properties:
LogGroupName: !Sub /aws/api-gateway/${GenBotFunction}
RetentionInDays: 30
GenBotRetrieveFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html
DependsOn:
- GenBotImagesBucket
Properties:
FunctionName: genbot-retrieve
CodeUri: ./
Handler: retrieve.handler
Description: Retrieves generated image
Timeout: 5
MemorySize: 256
FunctionUrlConfig:
AuthType: NONE
Policies:
- Statement:
- Sid: AllowImageBucketObjectGet
Effect: Allow
Action:
- s3:GetObject
- s3:ListBucket
Resource:
- 'arn:aws:s3:::case-consulting-mgmt-genbot-images'
- 'arn:aws:s3:::case-consulting-mgmt-genbot-images/*'
GenBotRetrieveFunctionLogGroup:
Type: AWS::Logs::LogGroup
DependsOn:
- GenBotRetrieveFunction
Properties:
LogGroupName: !Sub /aws/lambda/${GenBotRetrieveFunction}
RetentionInDays: 30
Outputs:
# ServerlessHttpApi is an implicit HTTP API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
GenBotApi:
Description: 'GenBot HTTP API Endpoint URL'
Value: !Sub 'https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/'
GenBotFunction:
Description: 'GenBot Lambda Function ARN'
Value: !GetAtt GenBotFunction.Arn
GenBotFunctionIamRole:
Description: 'Implicit IAM Role created for GenBot function'
Value: !GetAtt GenBotFunctionRole.Arn
GenBotRetrieveApi:
Description: 'GenBot Retrieve Lambda Function URL'
Value: !GetAtt GenBotRetrieveFunctionUrl.FunctionUrl
GenBotRetrieveFunction:
Description: 'GenBot Retrieve Lambda Function ARN'
Value: !GetAtt GenBotRetrieveFunction.Arn
GenBotRetrieveFunctionIamRole:
Description: 'Implicit IAM Role created for GenBot Retrieve function'
Value: !GetAtt GenBotRetrieveFunctionRole.Arn
GenBotImagesBucket:
Description: 'GenBot Images Bucket Name'
Value: !Ref GenBotImagesBucket