This is a self-contained, fully-reproducible project to forecast time series using serverless Lambda functions with TypeScript, AWS CDK, and Localstack.
- All environment settings required to execute the production and test commands should be provided stored in the
.env
file. - An example
.env.example
is provided with dummy values. Copy this file, rename it to.env
and provide the actual values, corresponding to the actual AWS account, API keys, etc.
- Make sure your AWS credentials for the profile specified in the environment variables is also registered in your
~/.aws/credentials
file.
npm run build
Compile Typescript to jsnpm run watch
Watch for changes to Typescript and compilenpm run test
Run the Jest unit tests
pip3 install awscli
to install orpip3 install --upgrade awscli
to upgrade
pip3 install localstack
to install localstack orpip3 install localstack --upgrade
to upgrade localstack to the latestlocalstack:start
Start the localhost container- Check localstack status http://localhost:4566/health
npm run cdklocal:bootstrap
Bootstrap the CDK stack to be able to deploy it to localstacknpm run cdklocal:deploy
Deploy the stack to localstacklocalstack:stop
Stop the localhost container
- Bucket commands
- Check forecast bucket's content
aws --endpoint-url=http://localhost:4566 s3 ls --recursive amos-forecast-data
- Add file to forecast bucket
aws --endpoint-url=http://localhost:4566 s3api put-object --bucket amos-forecast-data --key config/api.config.tiingo.json --body ./config/api.config.tiingo.json
aws --endpoint-url=http://localhost:4566 s3api put-object --bucket amos-forecast-data --key config/api.config.alphavantage.json --body ./config/api.config.alphavantage.json
- Check forecast bucket's content
- Queue commands
- Create queue
aws --endpoint-url=http://localhost:4566 sqs purge-queue --queue-url http://localhost:4566/000000000000/amos-queue.fifo
- Get queue url
aws --endpoint-url=http://localhost:4566 sqs get-queue-url --queue-name amos-queue.fifo
- Purge queue
aws --endpoint-url=http://localhost:4566 sqs purge-queue --queue-url http://localhost:4566/000000000000/amos-queue.fifo
- List queues
aws --endpoint-url=http://localhost:4566 sqs list-queues
- Create queue
npm run cdk:bootstrap
Bootstrap the CDK stack to be able to deploy it to AWSnpm run cdk:deploy
Deploy the stack to AWS
npm
scripts are provided to run the tests. You can also use thejest
extension invscode
to run tests individually.- Prerequisite: make sure
localstack
is up and running properly before executing tests. See sectionDeploy to localstack
above.
To execute the state machine manually, provide input in JSON format. It should be an object with this structure (values can vary, though).
Dataset State Machine Input Example
{
"skipQueueing": false,
"downloadStartDate": "2010-01-01",
"downloadEndDate": "0d"
}
Forecast State Machine Input Example
{
"import": { "enabled": false },
"predictor": { "enabled": false },
"forecast": { "enabled": false },
"export": { "enabled": false },
"analyze": { "enabled": false, "rebuild": true}
}
- Datasets https://github.com/awsdocs/amazon-forecast-developer-guide/blob/main/doc_source/howitworks-datasets-groups.md https://github.com/aws-samples/amazon-forecast-samples/blob/master/notebooks/basic/Tutorial/1.Getting_Data_Ready.ipynb
- Custom Resources https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/custom-resources https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/custom-resources/test/provider-framework/integration-test-fixtures/s3-file-handler/index.ts
This repository expands on several original ideas and guidance provided by these blog post and accompanying repositories.