Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
260 lines (260 sloc) 8.1 KB
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Resources:
Api:
Type: AWS::Serverless::Api
Properties:
Name: !Sub
- ${ResourceName} From Stack ${StackTagName} Environment ${EnvironmentTagName}
- ResourceName: Api
StageName: !Ref EnvironmentAPIGatewayStageName
DefinitionBody:
swagger: '2.0'
info: {}
paths:
/file:
get:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetFile.Arn}/invocations
responses: {}
post:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${CreateNewFile.Arn}/invocations
responses: {}
/file/{id}:
delete:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri: !Sub arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DeleteFile.Arn}/invocations
responses: {}
EndpointConfiguration: REGIONAL
TracingEnabled: true
Cors:
AllowHeaders: '''Authorization,Content-Type'''
AllowOrigin: '''*'''
Table:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
BillingMode: PAY_PER_REQUEST
KeySchema:
- AttributeName: id
KeyType: HASH
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
TableName: !Sub ${AWS::StackName}-Table
GetFile:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${AWS::StackName}-GetFile
Description: !Sub
- Stack ${StackTagName} Environment ${EnvironmentTagName} Function ${ResourceName}
- ResourceName: GetFile
CodeUri: src/GetFile
Handler: index.handler
Runtime: nodejs8.10
MemorySize: 3008
Timeout: 30
Tracing: Active
Policies:
- AWSXrayWriteOnlyAccess
- Version: 2012-10-17
Statement:
- Effect: Allow
Resource: !GetAtt Table.Arn
Action:
- dynamodb:GetItem
- dynamodb:Scan
Events:
ApiGETfile:
Type: Api
Properties:
Path: /file
Method: GET
RestApiId: !Ref Api
Environment:
Variables:
TABLE_NAME: !Ref Table
TABLE_ARN: !GetAtt Table.Arn
FrontEnd:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub ${AWS::StackName}-frontend
WebsiteConfiguration:
IndexDocument: index.html
FileStore:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub ${AWS::StackName}-filestore
ConvertToAudio:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${AWS::StackName}-ConvertToAudio
Description: !Sub
- Stack ${StackTagName} Environment ${EnvironmentTagName} Function ${ResourceName}
- ResourceName: ConvertToAudio
CodeUri: src/ConvertToAudio
Handler: index.handler
Runtime: nodejs8.10
MemorySize: 3008
Timeout: 300
Tracing: Active
Policies:
- AWSXrayWriteOnlyAccess
- Version: 2012-10-17
Statement:
- Effect: Allow
Resource: !Join
- ''
- - !GetAtt FileStore.Arn
- /*
Action:
- s3:PutObject
- s3:PutObjectAcl
- Version: 2012-10-17
Statement:
- Effect: Allow
Resource: !GetAtt Table.Arn
Action:
- dynamodb:UpdateItem
- Version: 2012-10-17
Statement:
- Effect: Allow
Resource: '*'
Action:
- polly:SynthesizeSpeech
Environment:
Variables:
BUCKET_NAME: !Ref FileStore
BUCKET_ARN: !GetAtt FileStore.Arn
TABLE_NAME: !Ref Table
TABLE_ARN: !GetAtt Table.Arn
CreateNewFile:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${AWS::StackName}-CreateNewFile
Description: !Sub
- Stack ${StackTagName} Environment ${EnvironmentTagName} Function ${ResourceName}
- ResourceName: CreateNewFile
CodeUri: src/CreateNewFile
Handler: index.handler
Runtime: nodejs8.10
MemorySize: 3008
Timeout: 300
Tracing: Active
Policies:
- AWSXrayWriteOnlyAccess
- Version: 2012-10-17
Statement:
- Effect: Allow
Resource: !GetAtt Table.Arn
Action:
- dynamodb:PutItem
- LambdaInvokePolicy:
FunctionName: !Ref ConvertToAudio
Events:
ApiPOSTfile:
Type: Api
Properties:
Path: /file
Method: POST
RestApiId: !Ref Api
Environment:
Variables:
TABLE_NAME: !Ref Table
TABLE_ARN: !GetAtt Table.Arn
FUNCTION_NAME: !Ref ConvertToAudio
FUNCTION_ARN: !GetAtt ConvertToAudio.Arn
PopulateFrontend:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${AWS::StackName}-PopulateFrontend
Description: !Sub
- Stack ${StackTagName} Environment ${EnvironmentTagName} Function ${ResourceName}
- ResourceName: PopulateFrontend
CodeUri: src/PopulateFrontend
Handler: index.handler
Runtime: nodejs10.x
MemorySize: 3008
Timeout: 600
Tracing: Active
Policies:
- AWSXrayWriteOnlyAccess
- S3CrudPolicy:
BucketName: !Ref FrontEnd
Environment:
Variables:
API_URL: !Sub https://${Api}.execute-api.${AWS::Region}.amazonaws.com/${Api.Stage}
BUCKET_NAME: !Ref FrontEnd
BUCKET_ARN: !GetAtt FrontEnd.Arn
PopulateFrontendDeployTrigger:
Type: Custom::FunctionDeployTrigger
Properties:
ServiceToken: !GetAtt PopulateFrontend.Arn
DeploymentTimestamp: !Ref DeploymentTimestamp
DeleteFile:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${AWS::StackName}-DeleteFile
Description: !Sub
- Stack ${StackTagName} Environment ${EnvironmentTagName} Function ${ResourceName}
- ResourceName: DeleteFile
CodeUri: src/DeleteFile
Handler: index.handler
Runtime: nodejs10.x
MemorySize: 3008
Timeout: 45
Tracing: Active
Policies:
- AWSXrayWriteOnlyAccess
- S3CrudPolicy:
BucketName: !Ref FileStore
- Version: 2012-10-17
Statement:
- Effect: Allow
Resource: !GetAtt Table.Arn
Action:
- dynamodb:GetItem
- dynamodb:DeleteItem
- Version: 2012-10-17
Statement:
- Effect: Allow
Resource: !Join
- ''
- - !GetAtt FileStore.Arn
- /*
Action:
- s3:DeleteObject
Events:
ApiDELETEfileid:
Type: Api
Properties:
Path: /file/{id}
Method: DELETE
RestApiId: !Ref Api
Environment:
Variables:
BUCKET_NAME: !Ref FileStore
BUCKET_ARN: !GetAtt FileStore.Arn
TABLE_NAME: !Ref Table
TABLE_ARN: !GetAtt Table.Arn
Parameters:
StackTagName:
Type: String
Description: Stack Name (injected by Stackery at deployment time)
EnvironmentTagName:
Type: String
Description: Environment Name (injected by Stackery at deployment time)
EnvironmentAPIGatewayStageName:
Type: String
Description: Environment name used for API Gateway Stage names (injected by Stackery at deployment time)
DeploymentTimestamp:
Type: Number
Description: Deployment preparation timestamp in milliseconds Since Epoch (injected by Stackery at deployment time)
You can’t perform that action at this time.