url-shortener

所属分类:FaaS/Serverless
开发工具:Python
文件大小:2177KB
下载次数:0
上传日期:2023-03-03 20:30:52
上 传 者sh-1993
说明:  来自zop.io的无服务器url缩短器
(serverless url-shortener from zoph.io)

文件列表:
Makefile (3477, 2023-03-04)
assets (0, 2023-03-04)
assets\demo-website.png (2137768, 2023-03-04)
assets\schema.drawio (41366, 2023-03-04)
assets\schema.drawio.png (86261, 2023-03-04)
backend (0, 2023-03-04)
backend\backend.yml (6994, 2023-03-04)
frontend (0, 2023-03-04)
frontend\favicon.ico (15406, 2023-03-04)
frontend\frontend.htm (550, 2023-03-04)
frontend\frontend.yml (4738, 2023-03-04)
frontend\index.htm (556, 2023-03-04)
frontend\js.js (1101, 2023-03-04)
frontend\styles.css (753, 2023-03-04)
shortener (0, 2023-03-04)
shortener\handlers.py (6910, 2023-03-04)
shortener\requirements.txt (18, 2023-03-04)
template.yml (2301, 2023-03-04)

# ”— url-shortener ## § Rationale This _yet another url-shortener_, is the one I'm using for [AWS Security Digest Newsletter](https://awssecuritydigest.com) to track click rate from my readers. I wasn't able to find an existing solution that match my needs so I crafted my own version, another excuse to learn something new ¤“. Try out this AWS serverless url-shortener for your own usage and see the benefits it can bring. It's perfect for shortening links and tracking analytics. Plus, contributions and pull requests are welcome. ## ’ Features 1. `Create` API 2. Companion static website (HTML + Javascript) - [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) and [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) compliant 3. Hits counter + Analytics (Persisted in DynamoDB) ## ” Powered by - Lambda function (Python ) + API Gateway - CloudFront + S3 + ACM - DynamoDB Table - CloudFormation + SAM ## “ Schema ![Architecture Schema](./assets/schema.drawio.png) ## Usage ### Pre-requirements 1. You will need to have an already issued AWS Certificate Manage (ACM) wildcard Certificate in `us-east-1` AWS region: `*.{your_domain}` 2. Configure the proper parameters in the `Makefile` like the Route53 hosted zone Id (`HostedZoneId`) #### Parameters | Parameters | Default Value | Description | | --------------- | ----------------- | --------------------------------------------------------------- | | Product | `url-shortener` | Product Name | | Project | `zophio` | Project Name | | Environment | `dev` | Environment Name | | MinChar | `3` | Minimum characters for the random shortened link id | | MaxChar | `3` | Maximum characters for the random shortened link id | | Domain | `zoph.io` | Desired Domain (must be linked to the `HostedZoneId` Parameter) | | SubDomain | `shortener` | Desired subdomain of the API | | HostedZoneId | `Required` | AWS Route53 `HostedZoneId` where your domain name belongs | | FallbackUrl | `https://zoph.io` | When the url does not exist, fallback url | | CertificateArn | `Required` | Arn of the Wildcard ACM Certificate (`us-east-1`) | | AWSRegion | `eu-west-1` | AWS Region | | AlertsRecipient | `Required` | Email of the recipient of CloudWatch Alarms | ### Deployment $ make deploy $ make setup_front ### How to shorten urls? #### Using Companion Static Website Go to the following website after the deployment (depends on your parameters :point_up_2:) Demo: [![DemoWebsite](assets/demo-website.png)](https://short.zph.app) - `https://short.{Domain}` #### Using the `Makefile` $ make url 'https://google.com' > Simple quotes are important #### Using `cURL` ```bash curl -X POST https://{subdomain}.{domain}/create/ \ --header "Content-Type: application/json" \ -d '{"long_url": "https://google.com"}' ``` ##### Response sample ```json { "created_at": "2023-01-17T13:37:00", "long_url": "https://zoph.io", "short_id": "dBC", "short_url": "https://{subdomain}.{domain}/dBC", "ttl": 1674561936 } ``` ## “– Reference - [Blog post](https://blog.ruanbekker.com/blog/2018/11/30/how-to-setup-a-serverless-url-shortener-with-api-gateway-lambda-and-dynamodb-on-aws/) - [Makefile](https://itecnote.com/tecnote/r-how-to-pass-argument-to-makefile-from-command-line/) - [CloudFront stack](https://github.com/aws-samples/amazon-cloudfront-secure-static-site/tree/master)

近期下载者

相关文件


收藏者