AWSTemplateFormatVersion: 2010-09-09 Transform: AWS::Serverless-2016-10-31 Description: AlleyCat - Database lookup APIs Parameters: DynamoDBtableName: Type: String Default: alleycat-races Resources: MyApi: Type: AWS::Serverless::HttpApi Properties: # CORS configuration - this is open for development only and should be restricted in prod. # See https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-httpapi-httpapicorsconfiguration.html CorsConfiguration: AllowMethods: - GET - POST - DELETE - OPTIONS AllowHeaders: - "*" AllowOrigins: - "*" ########################################## # Lambda functions # ########################################## GetRacesFunction: Type: AWS::Serverless::Function Properties: CodeUri: functions/ Handler: getRaces.handler Runtime: nodejs14.x Timeout: 3 MemorySize: 128 Environment: Variables: DDB_TABLE: !Ref DynamoDBtableName Policies: DynamoDBCrudPolicy: TableName: !Ref DynamoDBtableName Events: HttpGet: Type: HttpApi Properties: Path: '/getRaces' Method: get ApiId: !Ref MyApi GetLeaderboardFunction: Type: AWS::Serverless::Function Properties: CodeUri: functions/ Handler: getLeaderboard.handler Runtime: nodejs14.x Timeout: 3 MemorySize: 128 Environment: Variables: DDB_TABLE: !Ref DynamoDBtableName Policies: DynamoDBCrudPolicy: TableName: !Ref DynamoDBtableName Events: HttpGet: Type: HttpApi Properties: Path: '/leaderboard' Method: get ApiId: !Ref MyApi Outputs: APIendpoint: Description: HTTP API endpoint URL. Value: !Sub "https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com"