SDK client
To work with logs, you can configure your own SDK client using Python or Go.
For an SDK client, you can:
- specify configurations of the configured AWS CLI;
- override AWS CLI configurations;
- specify custom configurations.
Python
Go
AWS CLI configurations
Overridden AWS CLI configurations
Custom configurations
-
Open the CLI.
-
Install boto3 to configure dependencies:
pip install boto3 -
Create or open the client script file.
-
Add the script to the file. You can override the AWS CLI configurations in the script:
import boto3access_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>'— override the Access key. In the<access_key>parameter, specify the value of the Access key field from the S3 key you issued to the user; - optional:
secret_key = '<secret_key>'— override the Secret key. In the<secret_key>parameter, specify the value of the Secret key field from the S3 key you issued to the user; - optional:
region = '<pool>'— override the pool. In the<pool>parameter, specify the pool, for exampleru-9; <log_endpoint>— the URL for accessing the Logs service API. You can find the list of URLs in the Logs subsection of the URL List.
- optional:
-
Open the CLI.
-
Install boto3 to configure dependencies:
pip install boto3 -
Create or open the client script file.
-
Add the script to the file:
import boto3access_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>— the value of the Access key field from the S3 key that you issued to the user;<secret_key>— the value of the Secret key field from the S3 key that you issued to the user;<pool>— the pool, for exampleru-9;<log_endpoint>— the URL for accessing the Logs service API. You can find the list of URLs in the Logs subsection of the URL List.
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-v2go get github.com/aws/aws-sdk-go-v2/configgo get github.com/aws/aws-sdk-go-v2/service/cloudwatchlogsgo get github.com/aws/aws-sdk-go-v2/credentials -
Create or open the client script file.
-
Add the script to the file. The script will configure the client with the settings you specified 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("Failed to load config: %v", err)
}
client := cloudwatchlogs.NewFromConfig(cfg)
fmt.Println("CloudWatch Logs Client created:", client)
}
-
Open the CLI.
-
Download the packages to create the client:
go get github.com/aws/aws-sdk-go-v2go get github.com/aws/aws-sdk-go-v2/configgo get github.com/aws/aws-sdk-go-v2/service/cloudwatchlogsgo get github.com/aws/aws-sdk-go-v2/credentials -
Create or open the client script file.
-
Add the script to the file. You can override the 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("Unknown service: %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("Failed to load config: %v", err)
}
client := cloudwatchlogs.NewFromConfig(cfg)
fmt.Println("CloudWatch Logs Client created:", client)
}
Specify:
- optional:
accessKey := "<access_key>"— override the Access key. In the<access_key>parameter, specify the value of the Access key field from the S3 key that you issued to the user; - optional:
secretKey := "<secret_key>"— override the Secret key. In the<secret_key>parameter, specify the value of the Secret key field from the S3 key that you issued to the user; - optional:
region := "<pool>"— override the pool. In the<pool>parameter, specify a pool, for exampleru-9; <log_endpoint>— the URL for accessing the Logs service API. You can find the list of URLs in the Logs subsection of the URL List.
-
Open the CLI.
-
Download the packages to create the client:
go get github.com/aws/aws-sdk-go-v2go get github.com/aws/aws-sdk-go-v2/configgo get github.com/aws/aws-sdk-go-v2/service/cloudwatchlogsgo get github.com/aws/aws-sdk-go-v2/credentials -
Create or open the 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("Unknown service: %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("Failed to load config: %v", err)
}
client := cloudwatchlogs.NewFromConfig(cfg)
fmt.Println("CloudWatch Logs Client created:", client)
}
Specify:
<access_key>— the value of the Access key field from the S3 key that you issued to the user;<secret_key>— the value of the Secret key field from the S3 key that you issued to the user;<pool>— the pool for generating the API URL for the Logs service;<log_endpoint>— the URL for accessing the Logs service API. You can find the list of URLs in the Logs subsection of the URL List.