Skip to content

Commit

Permalink
Feature/issue 89 The timeseries Lambda is getting invoked every 15 se…
Browse files Browse the repository at this point in the history
…conds (#137)

* Add headers to API integration request and test 'User-Data' header for 'Elastic-Agent'

* Update unit tests for headers in event object

* Refine test for 'Elastic-Heartbeat' in Lambda event object

* Update changelog with issue

* Test for the presence of headers in the event object

* Pass header name in error response for cases where header is not found

* Use absolute path to test data rather then relative

---------

Co-authored-by: Frank Greguska <[email protected]>
  • Loading branch information
nikki-t and frankinspace authored Apr 2, 2024
1 parent 29f15c4 commit 671acff
Show file tree
Hide file tree
Showing 4 changed files with 417 additions and 302 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Issue 77 - Create UMM-S record for hydrocron
- Issue 89 - Pass headers to timeseries Lambda and test for 'Elastic-Heartbeat' in 'User-Agent' header
- Issue 24 - Indicate which collection version the data belongs to
- Issue 13 - Add SWORD version from shp.xml to DB entries
- Issue 85 - Add variable units to API response
Expand Down
10 changes: 9 additions & 1 deletion hydrocron/api/controllers/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,17 @@ def lambda_handler(event, context): # noqa: E501 # pylint: disable=W0613
"""

start = time.time()
print(f"Event - {event}")
print(f'Event - {event}')

results = {'http_code': '200 OK'}

try:
if event['body'] == {} and 'Elastic-Heartbeat' in event['headers']['User-Agent']:
return {}
except KeyError as e:
print(f'Error encountered with headers: {e}')
raise RequestError(f'400: Issue encountered with request header: {e}') from e

try:
feature = event['body']['feature']
feature_id = event['body']['feature_id']
Expand Down
23 changes: 16 additions & 7 deletions terraform/api-specification-templates/hydrocron_aws_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,23 @@ paths:
requestTemplates:
application/json: |-
#set($queryParams = $input.params().querystring)
#set($headerParams = $input.params().header)
{
"body" :
{
#foreach($paramName in $queryParams.keySet())
"$paramName": "$util.escapeJavaScript($queryParams.get($paramName))"
#if($foreach.hasNext),#end
#end
}}
"body" :
{
#foreach($paramName in $queryParams.keySet())
"$paramName": "$util.escapeJavaScript($queryParams.get($paramName))"
#if($foreach.hasNext),#end
#end
},
"headers" :
{
#foreach($header in $headerParams.keySet())
"$header": "$util.escapeJavaScript($input.params().header.get($header))"
#if($foreach.hasNext),#end
#end
}
}
passthroughBehavior: when_no_templates
httpMethod: POST
contentHandling: CONVERT_TO_TEXT
Expand Down
Loading

0 comments on commit 671acff

Please sign in to comment.