Posts

Showing posts with the label aws

Assign Domain on Route53 to CloudFront

Image
In this post, I am going to assign a domain name (on Route53) to the website hosted on S3 thru CloudFront ( prev post ). user <-> Route53       -> CloudFront -> S3 Issue & Validate Certificate Console > Certificate Manager (ACM) > Request a certificate Add domain names > Domain name: *.YOUR_DOMAIN > Next Select validation method > DNS validation  > Next Add tags > Review Review > Confirm and request Validation > Create record in Route 53 > Continue The validation will take a few minutes. Add CNAME to CloudFront Console > CloudFront > [cloud-front-id] > Edit Alternate Domain Names: www.YOUR_DOMAIN SSL Certificate: Custom SSL Certificate: (select your certificate) > Yes, Edit Add A Record Console > Route53 > Hosted zone > YOUR_DOMAIN > Create record: Record name: www Recird type: A & AAAAA (Turn on Alias ) Route traffic to: Alias to CloudFront distribution , Select distribution > Create rec...

Host Website on S3 thru CloudFront

In this post, I am going to describe how to host a website on S3, allowing the access from CloudFront for faster content distribution. user -> CloudFront -> S3 Create Bucket on S3 % mkdir web && cd web % echo 'Hello, World!' > index.html % aws s3 mb s3://YOUR_BUCKET_NAME % aws s3 cp index.html s3://YOUR_BUCKET_NAME Confirm that you cannot access the bucket directly. % curl https://s3.amazonaws.com/YOUR_BUCKET_NAME/index.html AccessDenied Create Distribution on CloudFront Console > CloudFront > Create Distribution > Get Started > Origin Domain Name: YOUR_BUCKET_NAME Restrict Bucket Access: Yes Origin Access Identity: Create a New Identity Grant Read Permissions on Bucket: Yes, Update Bucket Policy Default Root Object: index.html > Create Distribution This will take a few minutes. Access % aws cloudfront list-distributions | jq -r '.DistributionList.Items[0].DomainName' xxxxxxxxxxxxx.cloudfront.net % curl xxxxxxxxxxxxx.cloudfront.net Hello,...

List of Major Computing Services on AWS, GCP, and Azure

Here are some of the major services for cloud computing:  AWS GCP Azure other FaaS Lambda Cloud Functions Azure Functions k8s EKS GKE AKS PaaS Elastic Beanstalk GAE App Service Heroku IaaS EC2 GCE Virtual Machine Note: each hyperlink is for the related post in this blog. Pricing: Each provider/service has a free trial option under limited usage. They are categorized into Few-months Free or Always Free . FaaS and PaaS tends to have more Alway Free options, probably because of higher chances of vendor lock-in. The k8s services provide the control plains which are free or very cheap, but you need to pay for the worker nodes.

Chalice Built-in Authorizers: Try Sample

"Chalice supports multiple mechanisms for authorization ... A Built-in authorizer is used when you’d like to write your custom authorizer in Chalice" ( https://aws.github.io/chalice/topics/authorizers.html ). In this post, I am going to run the sample in the above page. create project % chalice new-project chalice_auth % cd chalice_auth app.py from chalice import Chalice, AuthResponse app = Chalice(app_name= 'chalice_auth' ) @ app.authorizer () def demo_auth (auth_request):     token = auth_request.token     if token == 'allow' :         return AuthResponse(routes=[ '/' ], principal_id= 'user' )     else :         return AuthResponse(routes=[], principal_id= 'user' ) @ app.route ( '/' , authorizer=demo_auth) def index ():     return { 'context' : app.current_request.context} @ app.route ( '/hello' ) def index ():     return { 'hello' : 'world' } The endpoint /hello is added for comparis...

REST API with Chalice + Pynamo

Image
In this post, I am going to deploy a sample REST API on AWS API Gateway, Lambda, and DynamoDB using Chalice and PynamoDB. Chalice: https://web-quickstart.blogspot.com/2021/03/aws-chalice.html Pynamo: https://web-quickstart.blogspot.com/2021/05/crud-dynamodb-from-python-pynamodb.html API spec The following methods will be served for CRUD operations: /users/  POST:   param: id name /users/{id}  GET:   response: id name    PUT:   param: name    DELETE create project % chalice new-project user_api % cd ./user_api prepare files % tree . ├── app.py ├── chalicelib │   ├── __init__.py │   └── user.py ├── docker-compose.yml └── requirements.txt # app.py from chalice import Chalice from chalice import ForbiddenError, NotFoundError from chalicelib.user import User app = Chalice(app_name= 'user_api' ) @ app.route ( '/users' , methods=[ 'POST' ]) def create_user ():     user_as_json = app.current_request.json_body ...

CRUD DynamoDB from Python (PynamoDB)

In this post, I am goint to use DynamoDB from PynamoDB. You may compare the code with  CRUD DynamoDB from Python (boto3) what is PynamoDB? PynamoDB is "a Pythonic interface for Amazon's DynamoDB" https://github.com/pynamodb/PynamoDB install % pip install pynamodb % pip list | grep pynamo pynamodb                           5.0.3 student.py You can define the entity like: from pynamodb.attributes import UnicodeAttribute from pynamodb.models import Model class Student (Model):   class Meta :     table_name = 'student'     host = 'http://localhost:8000' # region = 'us-east-1'     write_capacity_units = 5       read_capacity_units = 5     id = UnicodeAttribute(hash_key= True )   grade = UnicodeAttribute(null= True ) You may remove the host = localhost (and optionally specify the region) to run it on the cloud. test.py from student import Studen...