This project contains source code and supporting files for a serverless application - VTDLP ID Minting service. This service assign a new NOID to a record and update record with new information. See Usage section.
The application uses several AWS resources, including Lambda functions, a DynamoDB and an API Gateway API. These resources are defined in the template.yaml
file in this project.
-
GET
https://xxxx.execute-api.us-east-1.amazonaws.com/Prod/mint- API key is required.
-
POST
https://xxxx.execute-api.us-east-1.amazonaws.com/Prod/update- API key is required
- Parameters are required
Name Description long_url https://long_url short_url https://short_url noid NOID create_date %Y-%m-%dT%H:%M:%S e.g. 2020-03-23T17:31:35
Click Next to continue
Name | Description |
---|---|
Stack name | any valid name |
NSTableName | a DynamoDB table name |
NOIDNAA | a valid string. e.g. 53696 |
NOIDScheme | ark:/ |
NOIDTemplate | a valid string. e.g. eeddeede |
REGION | a valid AWS region. e.g. us-east-1 |
Leave it as is and click Next
Make sure all checkboxes under Capabilities section are CHECKED
Click Create stack
To use the SAM CLI, you need the following tools.
- SAM CLI - Install the SAM CLI
- Python 3 installed
- Docker - Install Docker community edition
To build and deploy your application for the first time, run the following in your shell:
sam build --use-container
Above command will build the source of the application. The SAM CLI installs dependencies defined in requirements.txt
, creates a deployment package, and saves it in the .aws-sam/build
folder.
To package the application, run the following in your shell:
sam package --output-template-file packaged.yaml --s3-bucket BUCKETNAME
Above command will package the application and upload it to the S3 bucket you specified.
Run the following in your shell to deploy the application to AWS:
sam deploy --template-file packaged.yaml --stack-name STACKNAME --s3-bucket BUCKETNAME --parameter-overrides 'NSTableName=tablename Region=us-east-1 NOIDNAA=12345 NOIDScheme=ark:/ NOIDTemplate=aabbcc' --capabilities CAPABILITY_IAM --region us-east-1
- Get a new NOID
curl -H "x-api-key:APIKEY" https://xxxx.execute-api.us-east-1.amazonaws.com/Prod/mint
- Output
{"message": "New NOID: 3c46gw18 is created."
- Update a record by NOID
curl -H "x-api-key: APIKEY" -X POST -d "long_url=YourURL&short_url=YourURL&noid=YourNOID&create_date=2020-03-23T17:31:35" https://xxxx.execute-api.us-east-1.amazonaws.com/Prod/update
- Output
{"message": "Rec 3q13c28n is updated."}
Tests are defined in the tests
folder in this project. Use PIP to install the test dependencies and run tests. You must have a env file: custom_pytest.ini
lambdatest$ pip install -r tests/requirements.txt --user
# unit test
lambdatest$ python -m pytest tests/unit -v -c custom_pytest.ini
To delete the sample application that you created, use the AWS CLI. Assuming you used your project name for the stack name, you can run the following:
aws cloudformation delete-stack --stack-name stackname