Skip to content

Commit

Permalink
Fixed order of data that's being streamed in
Browse files Browse the repository at this point in the history
  • Loading branch information
Tan committed Oct 7, 2019
1 parent 2f4943e commit d86ca96
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 9 deletions.
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ This demo application consists of the following components:

## High-Level Architecture

![Image of High-Level Architecture](blog_stock_dashboard.png)
![Image of High-Level Architecture](doc-images/blog_stock_dashboard.png)

# Local Installation

## Install the [AWS Amplify Framework CLI](https://aws-amplify.github.io/docs/)

```bash
npm install -g @aws-amplify/cli
amplify configure
```

## Clone the repo from [Github](https://github.com/jmgtan/stock_dashboard)
Expand Down Expand Up @@ -108,4 +107,33 @@ Update the following values:
* `cognito_backend_access_key`: value is `stockMonitoring/<env>/backend`
* `appsync_endpoint_url`: use the value from the file `src/aws-exports.js` in the `aws_appsync_graphqlEndpoint` variable
* `appsync_region`: use the value from the file `src/aws-exports.js` in the `aws_appsync_region` variable
* `data_feed_key`: value is `stockMonitoring/<env>/datafeed`
* `data_feed_key`: value is `stockMonitoring/<env>/datafeed`

## Deploy via CloudFormation

Create S3 bucket to serve as the staging area for deploying the Lambda function. This will be used by the AWS CloudFormation package command.

```bash
aws s3api create-bucket --bucket <staging bucket name> --create-bucket-configuration LocationConstraint=eu-west-1
```

Next we package and stage the Lambda function

```bash
cd processors
aws cloudformation package --template-file cf-template.yaml --s3-bucket <staging bucket name> --output-template-file packaged-template.yaml
```

Once the command succeeds you can then execute the deploy command

```bash
aws cloudformation deploy --template-file packaged-template.yaml --stack-name <stack name> --capabilities CAPABILITY_IAM
```

Once deployment completes, going to the CloudFormation console and into the stack, you should be able to see the list of resources that were created

![List of CloudFormation Resources](doc-images/cf-resources.png)

Clicking the Lambda function, you should be able to see the trigger, which is a CloudWatch scheduled event for every 30 mins.

![Lambda Trigger](doc-images/lambda-trigger.png)
File renamed without changes
Binary file added doc-images/cf-resources.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc-images/lambda-trigger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 3 additions & 5 deletions processors/GetIntradayPrices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const getPrices = async(apiKey, symbol) => {
});
}

return prices;
return prices.reverse();
}
}

Expand All @@ -89,7 +89,7 @@ const writePrices = async(client, prices) => {
}
}

const test = async() => {
exports.handler = async(event) => {
const sm = new AWS.SecretsManager();
const backendTokens = await getBackendTokens(sm);
const client = buildAppSyncClient(backendTokens);
Expand Down Expand Up @@ -120,6 +120,4 @@ const test = async() => {
}
}
} while (nextToken != null);
}

test();
}
13 changes: 13 additions & 0 deletions processors/GetIntradayPrices/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion processors/GetIntradayPrices/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"aws-sdk": "^2.512.0",
"axios": "^0.19.0",
"graphql-tag": "^2.10.1",
"isomorphic-fetch": "^2.2.1"
"isomorphic-fetch": "^2.2.1",
"moment-timezone": "^0.5.26"
}
}
27 changes: 27 additions & 0 deletions processors/cf-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Resources:
GetIntradayPricesFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
CodeUri: GetIntradayPrices/
Runtime: nodejs10.x
MemorySize: 256
Timeout: 120
Policies:
- AWSLambdaExecute
- Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Action:
- secretsmanager:GetSecretValue
- cognito-idp:AdminInitiateAuth
Resource: '*'
Events:
ScheduledExec:
Type: Schedule
Properties:
Schedule: rate(30 minutes)
Name: GetIntradayPricesSchedule
Enabled: true
27 changes: 27 additions & 0 deletions processors/packaged-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
GetIntradayPricesFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
CodeUri: s3://jmgtan-local-stock-dash/a8249a09aa05066b1adddd840b3e9b4e
Runtime: nodejs10.x
MemorySize: 256
Timeout: 120
Policies:
- AWSLambdaExecute
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- secretsmanager:GetSecretValue
- cognito-idp:AdminInitiateAuth
Resource: '*'
Events:
ScheduledExec:
Type: Schedule
Properties:
Schedule: rate(30 minutes)
Name: GetIntradayPricesSchedule
Enabled: true

0 comments on commit d86ca96

Please sign in to comment.