This project contains source code and supporting files for a serverless application - VTDLP resolution service. This service resolves VTDLP's permanent link. For example, it redirects http://idn.lib.vt.edu/ark:/53696/kr10gt01
to https://iawa.lib.vt.edu/archive/kr10gt01
.
The application uses several AWS resources, including Lambda functions and an API Gateway API. These resources are defined in the template.yaml
file in this project.
- app.py: Handle URL redirection
GET
https://xxxx.execute-api.us-east-1.amazonaws.com/Prod/{arklabel}/53696/{shortid}- arklabel:
ark:
- shortid:
Noid
- arklabel:
Click Next to continue
Name | Description |
---|---|
Stack name | any valid name |
TargetTable | a DynamoDB table |
Image404 | 404 Image URL |
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 'TargetTableName=resolutiontable Region=us-east-1 Image404=https://images/404.jpg' --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM --region us-east-1
- URL redirection
curl https://xxxxx.execute-api.us-east-1.amazonaws.com/Prod/ark:/53696/kr10gt01
- Output
{"statusCode": 301, "location": "https://iawa.lib.vt.edu/archive/kr10gt01"}
ps. Setting up custom domain names (e.g. http://idn.lib.vt.edu ) for REST APIs. Guide
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 resolution-service