Customize SDK client
You can set up your own SDK client in Python or Go to work with logs.
For the SDK client, you can:
- Set the configurations of the customized AWS CLI;
- Override AWS CLI configurations;
- set custom configurations.
Python
Go
AWS CLI Configuration
Overridden AWS CLI configurations
Custom configurations
-
Open the CLI.
-
Install boto3 to customize dependencies:
pip install boto3 -
Open an existing script file or create a new one.
-
Copy the script to a file. You can override AWS CLI configurations in the script:
import boto3
access_key = '<access_key>'
secret_key = '<secret_key>'
region = '<pool>'
client = boto3.client(
'logs',
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
region_name=region,
endpoint_url=f'https://{region}.logs.selcloud.ru'
)Specify:
- optional:
<access_key>— the value of the Access key field from the S3 key you issued to the user; - optional:
<secret_key>— the value of the Secret key field from the S3 key you issued to the user; - optional:
<pool>— a pool for generating URLs for accessing the Logi service (e.g.,ru-8).
- optional:
-
Open the CLI.
-
Install boto3 to customize dependencies:
pip install boto3 -
Open an existing script file or create a new one.
-
Copy the script into a file:
import boto3
access_key = '<access_key>'
secret_key = '<secret_key>'
region = '<pool>'
client = boto3.client(
'logs',
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
region_name=region,
endpoint_url=f'https://{region}.logs.selcloud.ru'
)Specify:
<access_key>— field value Access key from the S3 key you issued to the user;<secret_key>— field value Secret key from the S3 key you issued to the user;<pool>— pool for generating URL address to the Logi service (e.g,ru-8).
AWS CLI configurations
Overridden AWS CLI configurations
Custom configurations
-
Open the CLI.
-
Download the packages to create the client:
go get github.com/aws/aws-sdk-go-v2
go get github.com/aws/aws-sdk-go-v2/config
go get github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs
go get github.com/aws/aws-sdk-go-v2/credentials -
Open an existing script file or create a new one.
-
Copy the script to a file.The script will configure the client with the configurations you set for the AWS CLI:
package main
import (
"context"
"fmt"
"log"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
)
func main() {
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
log.Fatalf("Ошибка загрузки конфигурации: %v", err)
}
client := cloudwatchlogs.NewFromConfig(cfg)
fmt.Println("CloudWatch Logs Сlient создан:", client)
}
-
Open the CLI.
-
Download the packages to create the client:
go get github.com/aws/aws-sdk-go-v2
go get github.com/aws/aws-sdk-go-v2/config
go get github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs
go get github.com/aws/aws-sdk-go-v2/credentials -
Open an existing script file or create a new one.
-
Copy the script to a file. You can override AWS CLI configurations in the script:
package main
import (
"context"
"fmt"
"log"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
)
func main() {
accessKey := "<access_key>"
secretKey := "<secret_key>"
region := "<pool>"
endpoint := fmt.Sprintf("https://%s.logs.selcloud.ru", region)
customResolver := aws.EndpointResolverFunc(func(service, region string) (aws.Endpoint, error) {
if service == cloudwatchlogs.ServiceID {
return aws.Endpoint{
URL: endpoint,
SigningRegion: region,
}, nil
}
return aws.Endpoint{}, fmt.Errorf("Неизвестный сервис: %s", service)
})
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithRegion(region),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accessKey, secretKey, "")),
config.WithEndpointResolver(customResolver),
)
if err != nil {
log.Fatalf("Ошибка загрузки конфигурации: %v", err)
}
client := cloudwatchlogs.NewFromConfig(cfg)
fmt.Println("CloudWatch Logs Client создан:", client)
}
Specify:
- optional:
<access_key>— the value of the Access key field from the S3 key you issued to the user; - optional:
<secret_key>— the value of the Secret key field from the S3 key you issued to the user; - optional:
<pool>— a pool for generating URLs for accessing the Logi service (e.g.,ru-8).
-
Open the CLI.
-
Download the packages to create the client:
go get github.com/aws/aws-sdk-go-v2
go get github.com/aws/aws-sdk-go-v2/config
go get github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs
go get github.com/aws/aws-sdk-go-v2/credentials -
Open an existing script file or create a new one.
-
Copy the script into a file:
package main
import (
"context"
"fmt"
"log"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
)
func main() {
accessKey := "<access_key>"
secretKey := "<secret_key>"
region := "<pool>"
endpoint := fmt.Sprintf("https://%s.logs.selcloud.ru", region)
customResolver := aws.EndpointResolverFunc(func(service, region string) (aws.Endpoint, error) {
if service == cloudwatchlogs.ServiceID {
return aws.Endpoint{
URL: endpoint,
SigningRegion: region,
}, nil
}
return aws.Endpoint{}, fmt.Errorf("Неизвестный сервис: %s", service)
})
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithRegion(region),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accessKey, secretKey, "")),
config.WithEndpointResolver(customResolver),
)
if err != nil {
log.Fatalf("Ошибка загрузки конфигурации: %v", err)
}
client := cloudwatchlogs.NewFromConfig(cfg)
fmt.Println("CloudWatch Logs Client создан:", client)
}
Specify:
<access_key>— field value Access key from the S3 key you issued to the user;<secret_key>— field value Secret key from the S3 key you issued to the user;<pool>— pool for generating URL address to the Logi service (e.g,ru-8).