Found 26504 Articles for Server Side Programming

How to use Boto3 and AWS Resource to determine whether a root bucket exists in S3?

Ashish Anand
Updated on 22-Mar-2021 07:35:30

2K+ Views

Problem Statement − Use Boto3 library in Python to determine whether a root bucket exists in S3 or not.Example − Bucket_1 exists or not in S3.Approach/Algorithm to solve this problemStep 1 − Import boto3 and botocore exceptions to handle exceptions.Step 2 − Create an AWS session using boto3 library.Step 3 − Create an AWS resource for S3.Step 4 − Use the function head_bucket(). It returns 200 OK if the bucket exists and the user has permission to access it. Otherwise, the response would be 403 Forbidden or 404 Not Found.Step 5 − Handle the exception based on the response code.Step 6 ... Read More

How to use Boto3 to get a list of buckets present in S3 using AWS Client?

Ashish Anand
Updated on 22-Mar-2021 07:35:09

7K+ Views

Problem Statement − Use Boto3 library in Python to get the list of all buckets present in AWSExample − Get the name of buckets like – BUCKET_1, BUCKET2, BUCKET_3Approach/Algorithm to solve this problemStep 1 − Import boto3 and botocore exceptions to handle exceptions.Step 2 − Create an AWS session using Boto3 library.Step 3 − Create an AWS client for S3.Step 4 − Use the function list_buckets() to store all the properties of buckets in a dictionary like ResponseMetadata, bucketsStep 5 − Use for loop to get only bucket-specific details from the dictionary like Name, Creation Date, etc.Step 6 − Now, retrieve ... Read More

How to use Boto3 library in Python to get the list of buckets present in AWS S3?

Ashish Anand
Updated on 22-Mar-2021 07:33:34

404 Views

Problem Statement − Use boto3 library in Python to get the list of all buckets present in AWS.Example − Get the name of buckets like – BUCKET_1, BUCKET2, BUCKET_3Approach/Algorithm to solve this problemStep 1 − Import boto3 and botocore exceptions to handle exceptions.Step 2 − Create an AWS session using Boto3 library.Step 3 − Create an AWS resource for S3Step 4 − Use the function buckets.all() to list out the bucket names.Step 5 − Handle any unwanted exception, if it occursStep 6 − Return the list of buckets_namevExampleThe following code gets the list of buckets present in S3 −import boto3 ... Read More

How to connect different AWS services using Boto3 library in Python?

Ashish Anand
Updated on 22-Mar-2021 07:32:39

753 Views

In this article, we will see how you can use Boto3 library in Python to connect with different AWS services.ExampleConnect with AWS S3.Connect with AWS Glue JobConnect with AWS SQS and many more.Approach/Algorithm to solve this problemStep 1 − Create an AWS session using Boto3 library.Step 2 − Pass the AWS service name in client to get a low-level service access.Or, pass the AWS service name in resource to get high-level object-oriented service access/highlevel interface.ExampleThe following code connects with different AWS services −import boto3 # To get AWS Client def getconnection_AWSClient(service_name):    session = boto3.session.Session()    # User can pass ... Read More

How to create an AWS session using Boto3 library in Python?

Ashish Anand
Updated on 22-Mar-2021 07:32:06

5K+ Views

When a user wants to use AWS services using lambda or programming code, a session needs to set up first to access AWS services.An AWS session could be default as well as customized based on needs.Problem Statement − Use Boto3 library in Python to create an AWS session.Approach/Algorithm to solve this problemStep 1 − To create an AWS session, first set up authentication credentials. Users can find it in IAM console or alternatively, create the credential file manually. By default, its location is at ~/.aws/credentialsExample[default] aws_access_key_id = YOUR_ACCESS_KEY aws_secret_access_key = YOUR_SECRET_ACCESS_KEY aws_session_token = YOUR_SESSION_TOKEN region = REGION_NAMEStep 2 − Install ... Read More

Golang program to calculate the absolute and scale of a vertex.

Rishikesh Kumar Rishi
Updated on 18-Mar-2021 12:27:19

271 Views

ExampleAbs(x, y) => √(x)2+(y)2Scale(f) => (x*f, y*f)ApproachDefine a vertex as a struct.Initialize the vertex with some x and value.Define a method to calculate absolute(x, y).Define a method to calculate scale(x*f, y*f).Example Live Demopackage main import (    "fmt"    "math" ) type Vertex struct {    X, Y float64 } func Abs(v Vertex) float64{    return math.Sqrt(v.X*v.X + v.Y*v.Y) } func Scale(v *Vertex, f float64) {    v.X = v.X * f    v.Y = v.Y * f } func main() {    v := Vertex{3, 4}    fmt.Println("Given vertex is: ", v)    fmt.Println("Absolute value of given vertex is: ", ... Read More

Golang program to traverse a given input array, with Boolean flag, using arrays and struct.

Rishikesh Kumar Rishi
Updated on 18-Mar-2021 12:25:52

229 Views

ExampleApproachAsk the user to enter the size of array.Make a string array of given size.Ask the user to enter elements.At the end, print the array.Example Live Demopackage main import "fmt" func main(){    arr := []int{10, 20, 30, 60, 40, 50}    boolArr := []bool{true, false, true, false, true, false}    fmt.Println("Input Array is: ", arr)    fmt.Println("Input Boolean Array is: ", boolArr)    visitedArray := []struct{       i int       b bool    }{       {10, true},       {20, false},       {30, true},       {60, false},     ... Read More

Golang Program to create a string array that takes inputs from users.

Rishikesh Kumar Rishi
Updated on 18-Mar-2021 12:23:25

970 Views

ExampleApproachAsk the user to enter the size of array.Make a string array of given size.Ask the user to enter the elements.At the end, print the array.Example Live Demopackage main import (    "fmt" ) func main(){    fmt.Printf("Enter size of your array: ")    var size int    fmt.Scanln(&size)    var arr = make([]string, size)    for i:=0; i

Golang program to create an integer array that takes inputs from users.

Rishikesh Kumar Rishi
Updated on 18-Mar-2021 12:21:49

4K+ Views

ExampleApproachAsk the user to enter the size of array.Make an integer array of given size.Ask the user to enter elements.At the end, print the array.Example Live Demopackage main import (    "fmt" ) func main(){    fmt.Printf("Enter size of your array: ")    var size int    fmt.Scanln(&size)    var arr = make([]int, size)    for i:=0; i

Golang program to count the number of nodes in a doubly linked list.

Rishikesh Kumar Rishi
Updated on 18-Mar-2021 12:19:51

146 Views

ExamplesApproachStep 1 − Define a method that accepts the head of a doubly linked list.Step 2 − Initialize temp:=head, count:=0Step 3 − Iterate temp until it becomes nil.Step 4 − Increase count by 1.Step 5 − At the end, print count.Example Live Demopackage main import "fmt" type Node struct {    prev *Node    value int    next *Node } func CreateNewNode(value int) *Node{    var node Node    node.next = nil    node.value = value    node.prev = nil    return &node } func TraverseDoublyLL(head * Node){    // Forward Traversal    fmt.Printf("Doubly Linked List: ")    count := 0 ... Read More

Advertisements