api_spec.json 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. {
  2. "openapi": "3.0.0",
  3. "info": {
  4. "title": "AWSMetricsServiceApi",
  5. "description": "Service API for the data analytics pipeline defined by the AWS Metrics Gem",
  6. "version": "1.0.1"
  7. },
  8. "x-amazon-apigateway-request-validators": {
  9. "all": {
  10. "validateRequestBody": true,
  11. "validateRequestParameters": true
  12. }
  13. },
  14. "x-amazon-apigateway-request-validator": "all",
  15. "paths": {
  16. "/producer/events": {
  17. "post": {
  18. "x-amazon-apigateway-auth": {
  19. "type": "AWS_IAM"
  20. },
  21. "x-amazon-apigateway-integration": {
  22. "credentials": "${ApiGatewayRoleArn}",
  23. "uri": "arn:${AWS::Partition}:apigateway:${AWS::Region}:kinesis:action/PutRecords",
  24. "httpMethod": "POST",
  25. "responses": {
  26. "200": {
  27. "statusCode": "200",
  28. "responseTemplates": {
  29. "application/json": "#set($response = $input.path('$'))\n#set($records = $input.json('$.Records'))\n{\n \"result\": {\n \"total\": $response.Records.size(),\n \"failed_record_count\": $input.json('$.FailedRecordCount'),\n \"events\": [\n #foreach($record in $response.Records)\n #if($record.ErrorCode != $null)\n {\n \"result\": \"Error\", \n \"error_code\": \"$record.ErrorCode\"\n }\n #else\n {\n \"result\": \"Ok\"\n }\n #end\n #if($foreach.hasNext),#end\n #end\n ]\n }\n}\n"
  30. }
  31. },
  32. "4\\d{2}": {
  33. "statusCode": "400",
  34. "responseTemplates": {
  35. "application/json": "#set($inputRoot = $input.path('$'))\n{\n \"type\": \"BadRequest\",\n \"message\": $input.json('$.message')\n}\n"
  36. }
  37. },
  38. "5\\d{2}": {
  39. "statusCode": "500",
  40. "responseTemplates": {
  41. "application/json": "#set($inputRoot = $input.path('$'))\n{\n \"type\": $input.json('$.__type'),\n \"message\": $input.json('$.message')\n}\n"
  42. }
  43. }
  44. },
  45. "requestParameters": {
  46. "integration.request.header.Content-Type": "'x-amz-json-1.1'"
  47. },
  48. "requestTemplates": {
  49. "application/json": "{\n \"StreamName\": \"${InputStreamName}\",\n \"Records\": [\n #set($i = 0)\n #foreach($event in $input.path('$.events'))\n #set($data = $input.json(\"$.events[$i]\"))\n {\n \"Data\": \"$util.base64Encode($data)\",\n \"PartitionKey\": \"$event.application_id\"\n }#if($foreach.hasNext),#end\n #set($i = $i + 1)\n #end\n ]\n}\n"
  50. },
  51. "passthroughBehavior": "never",
  52. "type": "aws"
  53. },
  54. "operationId": "SendEvents",
  55. "requestBody": {
  56. "content": {
  57. "application/json": {
  58. "schema": {
  59. "$ref": "#/components/schemas/MetricsEventsBatchSchema"
  60. }
  61. }
  62. },
  63. "required": true
  64. },
  65. "responses": {
  66. "200": {
  67. "description": "Successful POST /producer/events",
  68. "content": {
  69. "application/json": {
  70. "schema": {
  71. "$ref": "#/components/schemas/PostMetricsEventsResponse"
  72. }
  73. }
  74. }
  75. },
  76. "400": {
  77. "description": "Bad Request Exception",
  78. "content": {
  79. "application/json": {
  80. "schema": {
  81. "$ref": "#/components/schemas/PostMetricsEventsError"
  82. }
  83. }
  84. }
  85. },
  86. "401": {
  87. "description": "Unauthorized Exception",
  88. "content": {
  89. "application/json": {
  90. "schema": {
  91. "$ref": "#/components/schemas/PostMetricsEventsError"
  92. }
  93. }
  94. }
  95. },
  96. "500": {
  97. "description": "Internal Server PostMetricsEventsError",
  98. "content": {
  99. "application/json": {
  100. "schema": {
  101. "$ref": "#/components/schemas/PostMetricsEventsError"
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }
  109. },
  110. "components": {
  111. "schemas": {
  112. "PostMetricsEventsError": {
  113. "type": "object",
  114. "properties": {
  115. "message": {
  116. "type": "string",
  117. "description": "Error message"
  118. },
  119. "type": {
  120. "type": "string",
  121. "description": "Error code from the API"
  122. }
  123. }
  124. },
  125. "MetricsEventsBatchSchema": {
  126. "title": "Batched Metrics Events Schema",
  127. "required": [
  128. "events"
  129. ],
  130. "type": "object",
  131. "properties": {
  132. "events": {
  133. "type": "array",
  134. "items": {
  135. "$ref": "#/components/schemas/MetricsEventSchema"
  136. }
  137. }
  138. }
  139. },
  140. "MetricsEventSchema": {
  141. "type": "object",
  142. "title": "AWSMetrics API Event Schema",
  143. "description": "Metrics Event sent to the service API",
  144. "required": [
  145. "application_id",
  146. "event_id",
  147. "event_name",
  148. "event_timestamp"
  149. ],
  150. "properties": {
  151. "application_id": {
  152. "type": "string",
  153. "pattern": "^[0-9-.]+-\\{[0-9A-F]{8}-[0-9A-F]{4}-[1-5][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\\}$",
  154. "description": "Identifier for the application that generated the event"
  155. },
  156. "event_id": {
  157. "type": "string",
  158. "pattern": "^\\{[0-9A-F]{8}-[0-9A-F]{4}-[1-5][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\\}$",
  159. "description": "A random UUID that uniquely identifies an event."
  160. },
  161. "event_name": {
  162. "type": "string",
  163. "pattern": "^[A-Za-z0-9-_.]+$",
  164. "description": "Name of the event that occurred"
  165. },
  166. "event_timestamp": {
  167. "type": "string",
  168. "pattern": "^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2})\\:(\\d{2})\\:(\\d{2})Z$",
  169. "description": "The time in seconds since the Unix epoch at which this event occurred (set by producer of event)."
  170. },
  171. "event_type": {
  172. "type": "string",
  173. "pattern": "^[A-Za-z0-9-_.]+$",
  174. "description": "Identifies the type of event"
  175. },
  176. "event_version": {
  177. "type": "string",
  178. "pattern": "^[A-Za-z0-9-_.]+$",
  179. "description": "An API version for this event format."
  180. },
  181. "event_data": {
  182. "type": "object",
  183. "description": "Custom metrics attributes defined by this event."
  184. }
  185. }
  186. },
  187. "PostMetricsEventsResponse": {
  188. "title": "Metrics Event Success Response Schema",
  189. "type": "object",
  190. "properties": {
  191. "failed_record_count": {
  192. "type": "number",
  193. "description": "Number of events that failed to be sent to the backend"
  194. },
  195. "events": {
  196. "type": "array",
  197. "items": {
  198. "$ref": "#/components/schemas/PostMetricsEventsResponseEntry"
  199. }
  200. },
  201. "total": {
  202. "type": "number",
  203. "description": "Total number of events that were processed in the request"
  204. }
  205. }
  206. },
  207. "PostMetricsEventsResponseEntry": {
  208. "type": "object",
  209. "properties": {
  210. "error_code": {
  211. "type": "string",
  212. "description": "Error code if the individual metrics event failed to be sent"
  213. },
  214. "result": {
  215. "type": "string",
  216. "description": "Result for the processed individual metrics event. Expected value: \"Error\" or \"Ok\""
  217. }
  218. }
  219. }
  220. }
  221. }
  222. }