Skip to content

Instantly share code, notes, and snippets.

@Nxtra

Nxtra/template.yaml

Created Sep 24, 2019
Embed
What would you like to do?
Integrating AWS SAM with OpenAPI
AWSTemplateFormatVersion : "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: Conference API Service
Globals:
Api:
Cors:
AllowMethods: "'*'"
AllowHeaders: "'Content-Type'"
AllowOrigin: "'*'"
Outputs:
ProdDataEndpoint:
Description: "API dev stage endpoint"
Value: !Sub "https://${ConferenceApiGateway}.execute-api.eu-west-1.amazonaws.com/dev/"
Resources:
ConferenceApiGateway:
Type: AWS::Serverless::Api
Properties:
StageName: dev
DefinitionBody:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: ./redoc/spec/openapi.yaml
TracingEnabled: true
CreateSessionFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: conference-create-session-lambda
Runtime: java8
Handler: be.ordina.conference.lambda.CreateSessionLambda::handleRequest
CodeUri: ./conference-create-session-lambda/target/conference-create-session-lambda-1.0.0-SNAPSHOT.jar
Timeout: 30
MemorySize: 1024
Tracing: Active
Events:
CreateSessionApi:
Type: Api
Properties:
RestApiId: !Ref "ConferenceApiGateway"
Path: /sessions
Method: POST
Policies:
- AWSLambdaBasicExecutionRole
- AWSXrayWriteOnlyAccess
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'dynamodb:PutItem'
- 'dynamodb:UpdateItem'
Resource:
'Fn::Join':
- ''
- - 'arn:aws:dynamodb:'
- Ref: 'AWS::Region'
- ':'
- Ref: 'AWS::AccountId'
- ':table/'
- Ref: SessionsDynamoDBTable
GetAllSessionsFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: conference-get-all-sessions-lambda
Runtime: java8
Handler: be.ordina.conference.lambda.GetLambda::handleRequest
CodeUri: ./conference-get-all-sessions-lambda/target/conference-get-all-sessions-lambda-1.0.0-SNAPSHOT.jar
Tracing: Active
Timeout: 30
MemorySize: 1024
Events:
GetAllSessionsApi:
Type: Api
Properties:
RestApiId: !Ref "ConferenceApiGateway"
Path: /sessions
Method: GET
Policies:
- AWSLambdaBasicExecutionRole
- AWSXrayWriteOnlyAccess
- DynamoDBReadPolicy:
TableName:
Ref: SessionsDynamoDBTable
SessionsDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: sessions
AttributeDefinitions:
- AttributeName: uuid
AttributeType: S
KeySchema:
- AttributeName: uuid
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment