![]() |
Cloudfront is an AWS Service that is used to reduce latency for delivering both static and dynamic content, When a user requests content that you’re serving with CloudFront, the request is routed to the edge location that provides the lowest latency (time delay), so that content is delivered with the best possible performance. If the content is already in the edge location with the lowest latency, CloudFront delivers it immediately. If the content is not in that edge location, CloudFront retrieves it from an origin that you’ve defined—such as an Amazon S3 bucket, a Media Package channel, or an HTTP server (for example, a web server)—that you have identified as the source for the definitive version of your content. To work with Cloudfront using the SDKs, we can use the Boto3 package in Python, If you’ve got multiple AWS profiles, you might struggle to use a specific profile while connecting, In this article, we’ll demonstrate how to choose a specific AWS profile while connecting with Cloudfront. Configure AWS CredentialsTo configure AWS profiles, we can use AWS cli, Follow the below steps to set up AWS profiles, and repeat the steps if you wanna add more profiles. Step 1: Login to AWS Console Step 2: Click on your username at the top right corner and click on Security Credentials Step 3: Under Access Keys, click on Create Access Key. Access Choose Command Line Interface (CLI). Add some description for it then Click on Create Step 4: Either copy the access key ID and Secret access key displayed on the screen or download the CSV file. aws configure --profile <profile-name> For example: aws configure --profile dillip-tech ![]() Configuring AWS Profile with custom name Connect To Cloudfront Using Specific AWS ProfileWhile connecting to cloudfront using boto3, there are various methods to use specific AWS profile:
Let’s get into the each method in-detail with practical example. Method 1: Specifying profile in SessionWe can specify the aws profile using the profile_name argument in Session class as mentioned in the below snippet, this will allow us to connect to cloudfront using that specific profile.
Method 2: Setting Default Profile In SessionWe can set the specific aws profile as default for AWS sessions using the setup_default_session method in boto3 and sessions or clients initiated after setting default profile will utilize the mentioned aws profile, you can observe the same the sample in the below snippet, this will allow us to connect to cloudfront using that specific profile.
Method 3: Setting Environment VariableThis will work Just like the above setup_default_session, but we need not mention it using any method instead we can set the default profile to use using the environment variable i.e AWS_PROFILE export AWS_PROFILE=my-profile And now the session or client initialized will use the my-profile as the aws profile for connecting, we need not mention aws profile anywhere.
Method 4: Using The Default ProfileBy default boto3 will try to initialize the client or session using the profile with name default, you can set the default profile by not specifying any profile while configuring or providing name as default aws configure ![]() Configure Default AWS profile Now you can initialize clients, which will use default profile if you didn’t specify AWS profile explicitly.
We’ve leant how to connect with cloudfront using specific profile with various possible methods, now you can leverage the cloudfront functionalities using the boto3, and deploy your files with ease, and you can work with different environments or projects using this profile specific connections. AWS profile when using boto3 to connect to CloudFront – FAQ’sWhat happens if I don’t use a specific profile and have multiple profiles configured?
What is the benefit of using a specific profile when connecting to CloudFront?
Is there a way to see which profile is currently being used by boto3?
|
Reffered: https://www.geeksforgeeks.org
Amazon Web Services |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |