Skip to content

Commit a217ea0

Browse files
authored
Update template.yaml
1 parent 2122a04 commit a217ea0

File tree

1 file changed

+82
-36
lines changed

1 file changed

+82
-36
lines changed
Lines changed: 82 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,96 @@
11
AWSTemplateFormatVersion: '2010-09-09'
22
Transform: AWS::Serverless-2016-10-31
3-
Description: Audio transcription using Amazon Transcribe
3+
Description: S3 to Lambda to Transcription Job
44

55
Resources:
6-
TranscribeFunction:
6+
AudioBucket:
7+
Type: AWS::S3::Bucket
8+
DependsOn: LambdaInvokePermission
9+
Properties:
10+
BucketName: !Sub "${AWS::StackName}-audio-uploads"
11+
NotificationConfiguration:
12+
LambdaConfigurations:
13+
- Event: s3:ObjectCreated:*
14+
Filter:
15+
S3Key:
16+
Rules:
17+
- Name: suffix
18+
Value: .mp3
19+
Function: !GetAtt TranscriptionFunction.Arn
20+
- Event: s3:ObjectCreated:*
21+
Filter:
22+
S3Key:
23+
Rules:
24+
- Name: suffix
25+
Value: .wav
26+
Function: !GetAtt TranscriptionFunction.Arn
27+
- Event: s3:ObjectCreated:*
28+
Filter:
29+
S3Key:
30+
Rules:
31+
- Name: suffix
32+
Value: .flac
33+
Function: !GetAtt TranscriptionFunction.Arn
34+
35+
TranscriptionFunctionRole:
36+
Type: AWS::IAM::Role
37+
Properties:
38+
AssumeRolePolicyDocument:
39+
Version: '2012-10-17'
40+
Statement:
41+
- Effect: Allow
42+
Principal:
43+
Service: lambda.amazonaws.com
44+
Action: sts:AssumeRole
45+
ManagedPolicyArns:
46+
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
47+
Policies:
48+
- PolicyName: S3AndTranscribeAccess
49+
PolicyDocument:
50+
Version: '2012-10-17'
51+
Statement:
52+
- Effect: Allow
53+
Action:
54+
- s3:GetObject
55+
- s3:PutObject
56+
- s3:ListBucket
57+
Resource:
58+
- !Sub "arn:aws:s3:::${AWS::StackName}-audio-uploads"
59+
- !Sub "arn:aws:s3:::${AWS::StackName}-audio-uploads/*"
60+
- Effect: Allow
61+
Action:
62+
- transcribe:StartTranscriptionJob
63+
- transcribe:GetTranscriptionJob
64+
Resource: "*"
65+
66+
TranscriptionFunction:
767
Type: AWS::Serverless::Function
868
Properties:
9-
CodeUri: src/
10-
Handler: app.lambda_handler
69+
CodeUri: ./src/
70+
Handler: app.handler
1171
Runtime: nodejs20.x
12-
Timeout: 900
72+
Timeout: 30
1373
MemorySize: 128
14-
Policies:
15-
- Statement:
16-
- Effect: Allow
17-
Action:
18-
- transcribe:StartTranscriptionJob
19-
- transcribe:GetTranscriptionJob
20-
Resource: '*'
21-
- Statement:
22-
- Effect: Allow
23-
Action:
24-
- s3:GetObject
25-
- s3:PutObject
26-
Resource: !Sub 'arn:aws:s3:::${AudioBucket}/*'
74+
Role: !GetAtt TranscriptionFunctionRole.Arn
2775
Environment:
2876
Variables:
29-
BUCKET_NAME: !Ref AudioBucket
30-
Events:
31-
TranscribeAPI:
32-
Type: Api
33-
Properties:
34-
Path: /transcribe
35-
Method: post
77+
BUCKET_NAME: !Sub "${AWS::StackName}-audio-uploads"
78+
REGION: !Ref AWS::Region
3679

37-
AudioBucket:
38-
Type: AWS::S3::Bucket
80+
LambdaInvokePermission:
81+
Type: AWS::Lambda::Permission
3982
Properties:
40-
CorsConfiguration:
41-
CorsRules:
42-
- AllowedHeaders: ['*']
43-
AllowedMethods: [GET, PUT, POST]
44-
AllowedOrigins: ['*']
45-
MaxAge: 3000
83+
FunctionName: !Ref TranscriptionFunction
84+
Action: lambda:InvokeFunction
85+
Principal: s3.amazonaws.com
86+
SourceAccount: !Ref AWS::AccountId
87+
SourceArn: !Sub "arn:aws:s3:::${AWS::StackName}-audio-uploads"
4688

4789
Outputs:
48-
TranscribeApi:
49-
Description: API Gateway endpoint URL
50-
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/transcribe"
90+
AudioBucketName:
91+
Description: "S3 bucket for audio uploads"
92+
Value: !Sub "${AWS::StackName}-audio-uploads"
93+
94+
TranscriptionFunctionName:
95+
Description: "Lambda function name"
96+
Value: !Ref TranscriptionFunction

0 commit comments

Comments
 (0)