Skip to content

Instantly share code, notes, and snippets.

@pacarvalho
Last active April 17, 2022 14:55
Show Gist options
  • Save pacarvalho/91447f01b42fcd73c8f2f755f3627a6e to your computer and use it in GitHub Desktop.
Save pacarvalho/91447f01b42fcd73c8f2f755f3627a6e to your computer and use it in GitHub Desktop.
AWS SAM Template for Video Processing Lambda
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
SAM project for Medium article about uploading and processing videos
Parameters:
EnvironmentValue:
AllowedValues:
- "staging"
- "production"
Default: "staging"
Description: "What environment is this?"
Type: String
Mappings:
Environments:
staging:
APIHOSTNAME: api-staging.example.com.br
LAMBDASHAREDSECRET: your-super-secret-shared-key
production:
APIHOSTNAME: api.example.com.br
LAMBDASHAREDSECRET: your-super-secret-shared-key
Resources:
VideoDerivativeGenerator:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/video_derivative_generator
Handler: index.handler
Runtime: nodejs12.x
MemorySize: 3008
Timeout: 600
Environment:
Variables:
VIDEO_MIME_TYPE: video/mp4
LAMBDA_SHARED_SECRET:
!FindInMap [Environments, !Ref EnvironmentValue, LAMBDASHAREDSECRET]
OUTPUT_BUCKET: !Sub "example-${EnvironmentValue}-videos"
API_HOSTNAME:
!FindInMap [Environments, !Ref EnvironmentValue, APIHOSTNAME]
Policies:
- AWSLambdaExecute # Managed Policy
- Version: "2012-10-17" # Policy Document
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
- s3:*
Resource: "*"
Events:
VideoUploaded:
Type: S3
Properties:
Bucket:
Ref: VideosBucket
Events:
- "s3:ObjectCreated:*"
Filter:
S3Key:
Rules:
- Name: prefix
Value: uploads/
Layers:
- arn:aws:lambda:<your-aws-region>:<your-aws-account-id>:layer:ffmpeg:1
VideosBucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName: !Sub "example-${EnvironmentValue}-videos"
AccelerateConfiguration:
AccelerationStatus: Enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment