serverless/r2s3-serverless.yaml [773:905]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            RestApiId: !Ref 'ApiGateway'
          Type: Api
      Handler: index.getVideos
      InlineCode: !Join
        - ''
        - - "\n"
          - "const AWS = require('aws-sdk');\n"
          - "\n"
          - "const {\n"
          - "  REGION,\n"
          - "  VIDEOS_TABLE_NAME\n"
          - "\n"
          - "} = process.env;\n"
          - "\n"
          - "const ddb = new AWS.DynamoDB();\n"
          - "\n"
          - "const response = (body, statusCode = 200) => {\n"
          - "    return {\n"
          - "      statusCode,\n"
          - "      headers: {\n"
          - "        'Content-Type': 'application/json',\n"
          - "        'Access-Control-Allow-Origin': '*'\n"
          - "      },\n"
          - "      body: JSON.stringify(body)\n"
          - "    };\n"
          - "  };\n"
          - "\n"
          - "// GET /videos and /video/:id\n"
          - "exports.getVideos = async (event) => {\n"
          - "    console.log(\"getVideos:\", JSON.stringify(event, null, 2));\n"
          - "  \n"
          - "    try {\n"
          - "  \n"
          - "  \n"
          - "      if (event.pathParameters && event.pathParameters.id) {\n"
          - "        console.log(\"getVideos > by id\");\n"
          - "  \n"
          - "        const params = {\n"
          - "          TableName: VIDEOS_TABLE_NAME,\n"
          - "          Key: {\n"
          - "            'Id': {\n"
          - "              'S': event.pathParameters.id\n"
          - "            }\n"
          - "          }\n"
          - "        };\n"
          - "  \n"
          - "        console.info(\"getVideos > by id > params:\", JSON.stringify(params,\
            \ null, 2));\n"
          - "  \n"
          - "        const result = await ddb.getItem(params).promise();\n"
          - "  \n"
          - "        console.info(\"getVideos > by id > result:\", JSON.stringify(result,\
            \ null, 2));\n"
          - "  \n"
          - "        // empty\n"
          - "        if (!result.Item) {\n"
          - "          return response(null, 404);\n"
          - "        }\n"
          - "  \n"
          - "        // removes types\n"
          - "        const filtered = {\n"
          - "          title: result.Item.Title ? result.Item.Title.S : '',\n"
          - "          subtitle: result.Item.Subtitle ? result.Item.Subtitle.S : '',\n"
          - "          id: result.Item.Id.S,\n"
          - "          created_on: result.Item.CreatedOn ? result.Item.CreatedOn.S\
            \ : '',\n"
          - "          playbackUrl: result.Item.PlaybackUrl ? result.Item.PlaybackUrl.S\
            \ : '',\n"
          - "          thumbnail: result.Item.Thumbnail ? result.Item.Thumbnail.S\
            \ : '',\n"
          - "          thumbnails: result.Item.Thumbnails ? result.Item.Thumbnails.SS\
            \ : [],\n"
          - "          views: result.Item.Viewers ? result.Item.Viewers.N : 0,\n"
          - "          length: result.Item.Length ? result.Item.Length.S : ''\n"
          - "        };\n"
          - "  \n"
          - "  \n"
          - "  \n"
          - "        console.info(\"getVideos > by Id > response:\", JSON.stringify(filtered,\
            \ null, 2));\n"
          - "  \n"
          - "        return response(filtered);\n"
          - "  \n"
          - "      }\n"
          - "  \n"
          - "      const result = await ddb.scan({ TableName: VIDEOS_TABLE_NAME }).promise();\n"
          - "  \n"
          - "  \n"
          - "      console.info(\"getVideos > result:\", JSON.stringify(result, null,\
            \ 2));\n"
          - "  \n"
          - "      // empty\n"
          - "      if (!result.Items) {\n"
          - "        return response({ \"vods\": [] });\n"
          - "      }\n"
          - "  \n"
          - "      // removes types\n"
          - "      let filteredItem;\n"
          - "      let filteredItems = [];\n"
          - "      let prop;\n"
          - "      for (prop in result.Items) {\n"
          - "        filteredItem = {\n"
          - "          id: result.Items[prop].Id.S,\n"
          - "          title: result.Items[prop].Title.S,\n"
          - "          subtitle: result.Items[prop].Subtitle.S,\n"
          - "          created_on: result.Items[prop].CreatedOn.S,\n"
          - "          playbackUrl: result.Items[prop].PlaybackUrl.S,\n"
          - "          thumbnail: result.Items[prop].Thumbnail ? result.Items[prop].Thumbnail.S\
            \ : '',\n"
          - "          thumbnails: result.Items[prop].Thumbnails ? result.Items[prop].Thumbnails.SS\
            \ : [],\n"
          - "          views: result.Items[prop].Viewers ? result.Items[prop].Viewers.N\
            \ : 0,\n"
          - "          length: result.Items[prop].Length ? result.Items[prop].Length.S\
            \ : ''\n"
          - "        };\n"
          - "  \n"
          - "  \n"
          - "        filteredItems.push(filteredItem);\n"
          - "  \n"
          - "      }\n"
          - "  \n"
          - "      console.info(\"getVideos > response:\", JSON.stringify(filteredItems,\
            \ null, 2));\n"
          - "      return response({ \"vods\": filteredItems });\n"
          - "  \n"
          - "    } catch (err) {\n"
          - "  \n"
          - "      console.info(\"getVideos > err:\", err);\n"
          - "      return response(err, 500);\n"
          - "  \n"
          - "    }\n"
          - '  };'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



serverless/r2s3-serverless.yaml [956:1088]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            RestApiId: !Ref 'ApiGateway'
          Type: Api
      Handler: index.getVideos
      InlineCode: !Join
        - ''
        - - "\n"
          - "const AWS = require('aws-sdk');\n"
          - "\n"
          - "const {\n"
          - "  REGION,\n"
          - "  VIDEOS_TABLE_NAME\n"
          - "\n"
          - "} = process.env;\n"
          - "\n"
          - "const ddb = new AWS.DynamoDB();\n"
          - "\n"
          - "const response = (body, statusCode = 200) => {\n"
          - "    return {\n"
          - "      statusCode,\n"
          - "      headers: {\n"
          - "        'Content-Type': 'application/json',\n"
          - "        'Access-Control-Allow-Origin': '*'\n"
          - "      },\n"
          - "      body: JSON.stringify(body)\n"
          - "    };\n"
          - "  };\n"
          - "\n"
          - "// GET /videos and /video/:id\n"
          - "exports.getVideos = async (event) => {\n"
          - "    console.log(\"getVideos:\", JSON.stringify(event, null, 2));\n"
          - "  \n"
          - "    try {\n"
          - "  \n"
          - "  \n"
          - "      if (event.pathParameters && event.pathParameters.id) {\n"
          - "        console.log(\"getVideos > by id\");\n"
          - "  \n"
          - "        const params = {\n"
          - "          TableName: VIDEOS_TABLE_NAME,\n"
          - "          Key: {\n"
          - "            'Id': {\n"
          - "              'S': event.pathParameters.id\n"
          - "            }\n"
          - "          }\n"
          - "        };\n"
          - "  \n"
          - "        console.info(\"getVideos > by id > params:\", JSON.stringify(params,\
            \ null, 2));\n"
          - "  \n"
          - "        const result = await ddb.getItem(params).promise();\n"
          - "  \n"
          - "        console.info(\"getVideos > by id > result:\", JSON.stringify(result,\
            \ null, 2));\n"
          - "  \n"
          - "        // empty\n"
          - "        if (!result.Item) {\n"
          - "          return response(null, 404);\n"
          - "        }\n"
          - "  \n"
          - "        // removes types\n"
          - "        const filtered = {\n"
          - "          title: result.Item.Title ? result.Item.Title.S : '',\n"
          - "          subtitle: result.Item.Subtitle ? result.Item.Subtitle.S : '',\n"
          - "          id: result.Item.Id.S,\n"
          - "          created_on: result.Item.CreatedOn ? result.Item.CreatedOn.S\
            \ : '',\n"
          - "          playbackUrl: result.Item.PlaybackUrl ? result.Item.PlaybackUrl.S\
            \ : '',\n"
          - "          thumbnail: result.Item.Thumbnail ? result.Item.Thumbnail.S\
            \ : '',\n"
          - "          thumbnails: result.Item.Thumbnails ? result.Item.Thumbnails.SS\
            \ : [],\n"
          - "          views: result.Item.Viewers ? result.Item.Viewers.N : 0,\n"
          - "          length: result.Item.Length ? result.Item.Length.S : ''\n"
          - "        };\n"
          - "  \n"
          - "  \n"
          - "  \n"
          - "        console.info(\"getVideos > by Id > response:\", JSON.stringify(filtered,\
            \ null, 2));\n"
          - "  \n"
          - "        return response(filtered);\n"
          - "  \n"
          - "      }\n"
          - "  \n"
          - "      const result = await ddb.scan({ TableName: VIDEOS_TABLE_NAME }).promise();\n"
          - "  \n"
          - "  \n"
          - "      console.info(\"getVideos > result:\", JSON.stringify(result, null,\
            \ 2));\n"
          - "  \n"
          - "      // empty\n"
          - "      if (!result.Items) {\n"
          - "        return response({ \"vods\": [] });\n"
          - "      }\n"
          - "  \n"
          - "      // removes types\n"
          - "      let filteredItem;\n"
          - "      let filteredItems = [];\n"
          - "      let prop;\n"
          - "      for (prop in result.Items) {\n"
          - "        filteredItem = {\n"
          - "          id: result.Items[prop].Id.S,\n"
          - "          title: result.Items[prop].Title.S,\n"
          - "          subtitle: result.Items[prop].Subtitle.S,\n"
          - "          created_on: result.Items[prop].CreatedOn.S,\n"
          - "          playbackUrl: result.Items[prop].PlaybackUrl.S,\n"
          - "          thumbnail: result.Items[prop].Thumbnail ? result.Items[prop].Thumbnail.S\
            \ : '',\n"
          - "          thumbnails: result.Items[prop].Thumbnails ? result.Items[prop].Thumbnails.SS\
            \ : [],\n"
          - "          views: result.Items[prop].Viewers ? result.Items[prop].Viewers.N\
            \ : 0,\n"
          - "          length: result.Items[prop].Length ? result.Items[prop].Length.S\
            \ : ''\n"
          - "        };\n"
          - "  \n"
          - "  \n"
          - "        filteredItems.push(filteredItem);\n"
          - "  \n"
          - "      }\n"
          - "  \n"
          - "      console.info(\"getVideos > response:\", JSON.stringify(filteredItems,\
            \ null, 2));\n"
          - "      return response({ \"vods\": filteredItems });\n"
          - "  \n"
          - "    } catch (err) {\n"
          - "  \n"
          - "      console.info(\"getVideos > err:\", err);\n"
          - "      return response(err, 500);\n"
          - "  \n"
          - "    }\n"
          - '  };'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



