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 configurations
Overridden AWS CLI configurations
Custom configurations
-
Open the CLI.
-
Install boto3 to customize dependencies:
pip install boto3 -
Create or open a client script file.
-
Add the script to the 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'<log_endpoint>'
)Specify:
- optional:
access_key = '<access_key>'- Access key override. In the parameter<access_key>specify the value of the Access key field from the S3 key you issued to the user; - optional:
secret_key = '<secret_key>'- Secret key override. In the parameter<secret_key>specify the value of the Secret key field from the S3-key you issued to the user; - optional:
region = '<pool>'- pool override . In the parameter<pool>specify the pool, for exampleru-9; <log_endpoint>- URL for accessing the API of the Logi service. The list of URLs can be found in the instruction List of URLs.
- optional:
-
Open the CLI.
-
Install boto3 to customize dependencies:
pip install boto3 -
Create or open a client script file.
-
Add the script to the 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'<log_endpoint>'
)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 exampleru-9;<log_endpoint>- URL for accessing the API of the Logi service. The list of URLs can be found in the instruction List of URLs.
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 -
Create or open a client script file.
-
Add the script to the 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 -
Create or open a client script file.
-
Add the script to the 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 := "<log_endpoint>"
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:
accessKey := "<access_key>"- Access key override. In the parameter<access_key>specify the value of the Access key field from the S3 key you issued to the user; - optional:
secretKey := "<secret_key>"- Secret key override. In the parameter<secret_key>specify the value of the Secret key field from the S3 key that you issued to the user; - optional:
region := "<pool>"- pool override . In the parameter<pool>specify the pool, for exampleru-9; <log_endpoint>- URL for accessing the API of the Logi service. The list of URLs can be found in the instruction List of URLs.
-
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 -
Create or open a client script file.
-
Add the script to the 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 := "<log_endpoint>"
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 URLs to the API of the Logov service;<log_endpoint>- URL for accessing the API of the Logi service. The list of URLs can be found in the instruction List of URLs.