Voiced by Amazon Polly |
Introduction
In this blog, we will discuss the traditional way of handling web forms using python with an example: uploading a file to AWS S3 using python boto3 package and python CGI package.
AWS S3 is a cloud service used to store static files in AWS. To upload any file to the S3 bucket, we need to log in to the AWS management console and open the S3 console. So, we will upload files to AWS S3 from the S3 console. To overcome all these login processes, we can create a web page to directly upload any file from any computer to our AWS S3 bucket. In this blog, we will be explaining this functionality using Python CGI script.
Customized Cloud Solutions to Drive your Business Success
- Cloud Migration
- Devops
- AIML & IoT
What is Boto3?
Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python. It allows Python developers to write software that uses services like Amazon S3 and Amazon EC2.
It gives the flexibility to access the AWS services from Python scripts. They are mainly used to automate the AWS services.
What is CGI?
CGI stands for Common Gateway Interface. It is an interface where web servers execute any program externally, generally processing client requests. These programs are primarily written using scripting languages like Python, Perl, PHP. These scripts are generally mentioned as CGI scripts.
Use Case
Its general use case occurs when a web client submits a form on a web page that uses CGI script as a backend. Then the submitted form data is sent to the web server using an HTTP request using HTTP methods like GET/POST, denoted in a URL that points to a CGI script. Then, the webserver that launches the CGI script file present in the URL in a new computer process passes the form data to that script. Now script gets processed, the response of the CGI script is returned in the form of HTML processed output and is sent to the webserver then web server sends the HTML output back to the web client from where the request is made.
Features of CGI:
- CGI is a method of interacting with HTML. It has the capability of processing the HTML written in a CGI script.
- CGI scripts are written using scripting languages like Python, Perl, C, or maybe just a simple shell script.
- Today CGI scripts are evolved as more browser friendly.
Advantages of CGI:
- As long as the applications follow the CGI standard, they may be built in any language and executed in any environment.
- Complicated tasks in CGI are now a lot easier to implement.
Disadvantages of CGI:
- Each webpage load in the CGI Interface incurs overhead because the program must be loaded into memory.
- CGI consumes a significant amount of processing time.
- For each form submitted, the client web page gets reloaded.
Prerequisites:
- Python IDE
- Python Boto3 package.
- Lambda Role access key and secrete key, which has AWS S3 full access.
Step-by-Step Guide:
->Create a folder that says “Project1”. Now create an HTML file say “form_upload.html” which contains below html form code.
Whenever the form is submitted, the file will be redirected to the address present in the action parameter. In addition, form data will be redirected to the python script using the POST method.
- CGI scripts must be in a particular directory, like cgi-bin. So now let’s create folder “cgi-bin” inside the “Project1” folder.
- Now go to the cgi-bin folder to write our Python script, let us name the file as
1 |
s3_file_upload.py |
- Now open the command prompt and go to the “Project1” folder, from here we will be starting our server which starts listening in port 8000 by using the below command.
1 |
python -m http.server --cgi |
- Now, open the browser and enter the URL form_uoload and choose a file, then press the upload button
- We can also check the response data from the command prompt while the server is running
Conclusion:
There are many ways to upload files to AWS S3 using the python boto3 package, but in this blog, we tried one of the ways, i.e., using traditional CGI script, which does not require any AWS API gateway configuration and serverless scripts like AWS lambda functions.
Get your new hires billable within 1-60 days. Experience our Capability Development Framework today.
- Cloud Training
- Customized Training
- Experiential Learning
About CloudThat
CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.
CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 850k+ professionals in 600+ cloud certifications and completed 500+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training Partner, AWS Migration Partner, AWS Data and Analytics Partner, AWS DevOps Competency Partner, AWS GenAI Competency Partner, Amazon QuickSight Service Delivery Partner, Amazon EKS Service Delivery Partner, AWS Microsoft Workload Partners, Amazon EC2 Service Delivery Partner, Amazon ECS Service Delivery Partner, AWS Glue Service Delivery Partner, Amazon Redshift Service Delivery Partner, AWS Control Tower Service Delivery Partner, AWS WAF Service Delivery Partner, Amazon CloudFront Service Delivery Partner, Amazon OpenSearch Service Delivery Partner, AWS DMS Service Delivery Partner, AWS Systems Manager Service Delivery Partner, Amazon RDS Service Delivery Partner, AWS CloudFormation Service Delivery Partner, AWS Config, Amazon EMR and many more.

WRITTEN BY Imraan Pattan
Imraan is a Software Developer working with CloudThat Technologies. He has worked on Python Projects using the Flask framework. He is interested in participating in competitive programming challenges and Hackathons. He loves programming and likes to explore different functionalities for creating backend applications.
Comments