AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Lionsnet - A VPC provisioning and subnetting calculator powered by AWS Lambda and DynamoDB.
Resources:
  GetConfigurationFn:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.main
      Runtime: nodejs6.10
      CodeUri: s3://lionsnet/dist.zip
      Policies: AmazonDynamoDBFullAccess
      Environment:
        Variables:
          TABLE_NAME: !Ref Table
      Events:
        GetConfigResource:
          Type: Api
          Properties:
            Path: /configuration
            Method: get
        PostConfigResource:
          Type: Api
          Properties:
            Path: /configuration
            Method: post
        PostVpcResource:
          Type: Api
          Properties:
            Path: /vpc
            Method: post
        GetVpcResource:
          Type: Api
          Properties:
            Path: /vpc/{vpcId}
            Method: get
        DeleteVpcResource:
          Type: Api
          Properties:
            Path: /vpc/{vpcId}
            Method: delete
        PostVpcSubnetResource:
          Type: Api
          Properties:
            Path: /vpc/{vpcId}/subnet
            Method: post
        DeleteVpcSubnetResource:
          Type: Api
          Properties:
            Path: /vpc/{vpcId}/subnet/{subnetNetworkAddress}
            Method: delete

  Table:
    Type: AWS::DynamoDB::Table
    Properties:
      AttributeDefinitions:
        -
          AttributeName: "vpcId"
          AttributeType: "S"
      KeySchema:
        -
          AttributeName: "vpcId"
          KeyType: "HASH"
      ProvisionedThroughput:
        ReadCapacityUnits: "5"
        WriteCapacityUnits: "5"
      TableName: 'lionsnet-vpc'
      Tags:
        - Key: Project
          Value: lionsnet
        - Key: Organization
          Value: Lionshead
