Python Dependencies Basics
Motivation
I need to replace Packer template with boto3 code that will replicate its functionality. The reason is that Packer license is confusing.
The Hive Python project is used to create a custom AMI image from a base image. The image will be made public and copied to all AWS regions. Anyone will be able to use the custom image for their own purposes for free.
OpenTofu template will use the custom AMI and provision the infrastructure on AWS for Rails 7.1 app.
Introduction
Using a requirements.txt file to install dependencies for your Python project is a best practice. This file has the project dependencies in a human readable format that can be installed using pip, Python’s package installer.
Specify Requirements
- Create a file named
requirements.txtin your project’s root directory.
boto3==1.34.78The latest version of boto3 can be found at boto3 versions.
Install Dependencies
- Install the dependencies using
pip:
pip install -r requirements.txtThis command will install boto3 and any other dependencies listed in your requirements.txt file. This approach ensures that your project’s environment is reproducible, making it easier for others to set up the project and for you to manage dependencies.
Verify Installation
- To check the version installed:
python -c "import boto3; print(boto3.__version__)"You can also use pip to check the version:
$ pip show boto3Name: boto3
Version: 1.34.78
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email:
License: Apache License 2.0
Location: /Users/bparanj/PycharmProjects/hive/.venv/lib/python3.12/site-packages
Requires: botocore, jmespath, s3transfer
Required-by: