Compare commits
2 Commits
bf2e2a295a
...
f499c6ed96
| Author | SHA1 | Date | |
|---|---|---|---|
| f499c6ed96 | |||
| 6333e5dcb2 |
47
.idea/workspace.xml
generated
47
.idea/workspace.xml
generated
@@ -5,26 +5,26 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="9a6512a2-4a65-46dc-ac79-ea908fa84d1f" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/.idea/aws.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/weather_forecase.iml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/Dockerfile" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/requirements.txt" beforeDir="false" afterPath="$PROJECT_DIR$/requirements.txt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/wheaterAPI.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/wheaterAPI.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/lambda_function/parse_to_dynamodb.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/lambda_function/parse_to_dynamodb.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Python Script" />
|
||||
<option value="AWS CloudFormation Template (YAML)" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="PREVIOUS_COMMIT_AUTHORS">
|
||||
<list>
|
||||
<option value="Jacob Fritsche <jacob@jacob-fritsche.de>" />
|
||||
<option value="hadoop <hadoop@jacob-fritsche.de>" />
|
||||
<option value="hadoop@jacob-fritsche.de" />
|
||||
<option value="Jacob Fritsche" />
|
||||
@@ -46,7 +46,7 @@
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
"last_opened_file_path": "C:/Users/jacob/PycharmProjects/GCP-Weather-Forecast",
|
||||
"last_opened_file_path": "C:/Users/jacob/PycharmProjects/AWS Weather Forecast",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
@@ -76,6 +76,7 @@
|
||||
<workItem from="1709141002289" duration="33000" />
|
||||
<workItem from="1709141085982" duration="184000" />
|
||||
<workItem from="1709141371555" duration="1607000" />
|
||||
<workItem from="1709143935553" duration="3109000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Initial code to get the weather data from the API">
|
||||
<option name="closed" value="true" />
|
||||
@@ -101,7 +102,23 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1708267319084</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="4" />
|
||||
<task id="LOCAL-00004" summary="Add lambda function to write json to dynamo db">
|
||||
<option name="closed" value="true" />
|
||||
<created>1709144200442</created>
|
||||
<option name="number" value="00004" />
|
||||
<option name="presentableId" value="LOCAL-00004" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1709144200442</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00005" summary="Add CloudFormation template to deploy the environment">
|
||||
<option name="closed" value="true" />
|
||||
<created>1709144394361</created>
|
||||
<option name="number" value="00005" />
|
||||
<option name="presentableId" value="LOCAL-00005" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1709144394361</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="6" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@@ -121,6 +138,8 @@
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="Initial code to get the weather data from the API" />
|
||||
<MESSAGE value="Add requirements.txt to control python package version" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Add requirements.txt to control python package version" />
|
||||
<MESSAGE value="Add lambda function to write json to dynamo db" />
|
||||
<MESSAGE value="Add CloudFormation template to deploy the environment" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Add CloudFormation template to deploy the environment" />
|
||||
</component>
|
||||
</project>
|
||||
36
src/cloudformation/API_to_DynamoDB.yaml
Normal file
36
src/cloudformation/API_to_DynamoDB.yaml
Normal file
@@ -0,0 +1,36 @@
|
||||
AWSTemplateFormatVersion: '2010-09-09'
|
||||
Resources:
|
||||
MyLambdaFunction:
|
||||
Type: 'AWS::Lambda::Function'
|
||||
Properties:
|
||||
Handler: lambda_function.handler
|
||||
Role: arn:aws:iam::123456789012:role/your-execution-role
|
||||
FunctionName: YourLambdaFunction
|
||||
Runtime: python3.8
|
||||
Code:
|
||||
S3Bucket: your-s3-bucket
|
||||
S3Key: your-code-package.zip
|
||||
|
||||
MyApi:
|
||||
Type: 'AWS::ApiGateway::RestApi'
|
||||
Properties:
|
||||
Name: YourAPI
|
||||
|
||||
MyApiResource:
|
||||
Type: 'AWS::ApiGateway::Resource'
|
||||
Properties:
|
||||
ParentId: !GetAtt MyApi.RootResourceId
|
||||
RestApiId: !Ref MyApi
|
||||
PathPart: your-resource
|
||||
|
||||
MyApiMethod:
|
||||
Type: 'AWS::ApiGateway::Method'
|
||||
Properties:
|
||||
AuthorizationType: NONE
|
||||
HttpMethod: POST
|
||||
ResourceId: !Ref MyApiResource
|
||||
RestApiId: !Ref MyApi
|
||||
Integration:
|
||||
IntegrationHttpMethod: POST
|
||||
Type: AWS_PROXY
|
||||
Uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyLambdaFunction.Arn}/invocations
|
||||
@@ -0,0 +1,61 @@
|
||||
import json
|
||||
|
||||
import boto3
|
||||
from datetime import datetime
|
||||
|
||||
class ForecastToDynamoDB()
|
||||
def __init__(self):
|
||||
self.dynamodb = boto3.resource('dynamodb')
|
||||
self.table = self.dynamodb.Table('Forecast')
|
||||
|
||||
def parse_current(self,json_data):
|
||||
|
||||
city = json_data['location']['name']
|
||||
region = json_data['location']['region']
|
||||
localtime = datetime.strptime(json_data['location']['localtime'], '%Y/%m-%d %H:%M')
|
||||
localtime_lastupdate = datetime.strptime(json_data['current']['last_updated'], '%Y/%m-%d %H:%M')
|
||||
current_temp_c = json_data['current']['temp_c']
|
||||
current_condition = json_root['current']['condition']['text']
|
||||
current_windspeed = json_data['current']['wind_kph']
|
||||
current_winddegree = json_data['current']['wind_degree']
|
||||
current_winddir = json_data['current']['wind_dir']
|
||||
current_feelslike_c = json_data['current']['feelslike_c']
|
||||
|
||||
response = self.table.put_item(
|
||||
Item = {
|
||||
'city': city,
|
||||
'region': region,
|
||||
'localtime': localtime,
|
||||
'localtime_lastupdated': localtime_lastupdate,
|
||||
'current_tmep_c': current_temp_c,
|
||||
'current_condition': current_condition,
|
||||
'current_windspeed': current_windspeed,
|
||||
'current_winddegree': current_winddegree,
|
||||
'current_winddir': current_winddir,
|
||||
'current_feelslike_c': current_feelslike_c,
|
||||
'current_json': json_data['current']
|
||||
}
|
||||
)
|
||||
|
||||
return response
|
||||
|
||||
def lambda_handler(event, context):
|
||||
|
||||
try:
|
||||
handler = ForecastToDynamoDB()
|
||||
|
||||
json_data = json.loads(event['body'])
|
||||
|
||||
response = handler.parse_current(json_data)
|
||||
|
||||
return {
|
||||
'statusCode': 200,
|
||||
'body': json.dump({'message':'Item is successfully written in DynamoDB'}),
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
return {
|
||||
'statusCode': 500,
|
||||
'body': json.dump({'error':str(e)}),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user