---
title: "SDK client"
sidebar_label: "SDK client"
description: "How to configure an SDK client to work with logs"
sidebar_position: 2
---

import Formbricks from '@theme/MDXComponents/Formbricks'
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import {TabItemLabel} from '@selectel/docux/components'

# 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.

<Tabs queryString="configure-clients">
  <TabItem value="python" default>
    <TabItemLabel>
      Python
    </TabItemLabel>

    <Tabs queryString="python-configs">
      <TabItem value="aws-cli-config">
        <TabItemLabel>
          AWS CLI configurations
        </TabItemLabel>

        1. Open the CLI.

        2. Install [boto3](https://github.com/boto/boto3/blob/develop/README.rst#quick-start) to configure dependencies:

           ```python
           pip install boto3
           ```

        3. [Configure the AWS CLI](/logs/tools/aws-cli.mdx).

        4. Configure the client with the configurations you specified for [AWS CLI](/logs/tools/aws-cli.mdx#configure-aws-cli):

           ```python
           import boto3

           client = boto3.client('logs')
           ```
      </TabItem>

      <TabItem value="overriden-config">
        <TabItemLabel>
          Overridden AWS CLI configurations
        </TabItemLabel>

        1. Open the CLI.

        2. Install [boto3](https://github.com/boto/boto3/blob/develop/README.rst#quick-start) to configure dependencies:

           ```python
           pip install boto3
           ```

        3. [Configure the AWS CLI](/logs/tools/aws-cli.mdx).

        4. Create or open the client script file.

        5. Add the script to the file. You can override the [AWS CLI](/logs/tools/aws-cli.mdx#configure-aws-cli) configurations in the script:

           ```python
           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>'` — 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](/logs/tools/aws-cli.mdx#issue-s3-key);
           * 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](/logs/tools/aws-cli.mdx#issue-s3-key);
           * optional: `region = '<pool>'` — override the [pool](/infrastructure/locations.mdx#pool). In the `<pool>` parameter, specify the pool, for example  `ru-9`;
           * `<log_endpoint>` — the URL for accessing the Logs service API. You can find the list of URLs in the [Logs](/api/urls/#logs) subsection of the [URL List](/api/urls/).
      </TabItem>

      <TabItem value="custom-config">
        <TabItemLabel>
          Custom configurations
        </TabItemLabel>

        1. Open the CLI.

        2. Install [boto3](https://github.com/boto/boto3/blob/develop/README.rst#quick-start) to configure dependencies:

           ```python
           pip install boto3
           ```

        3. Create or open the client script file.

        4. Add the script to the file:

           ```python
           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>` — the value of the **Access key** field from the S3 key that you [issued to the user](/logs/tools/aws-cli.mdx#issue-s3-key);
           * `<secret_key>` — the value of the **Secret key** field from the S3 key that you [issued to the user](/logs/tools/aws-cli.mdx#issue-s3-key);
           * `<pool>` — the [pool](/infrastructure/locations.mdx#pool), for example  `ru-9`;
           * `<log_endpoint>` — the URL for accessing the Logs service API. You can find the list of URLs in the [Logs](/api/urls/#logs) subsection of the [URL List](/api/urls/).
      </TabItem>
    </Tabs>
  </TabItem>

  <TabItem value="go" default>
    <TabItemLabel>
      Go
    </TabItemLabel>

    <Tabs>
      <TabItem value="aws-cli-config">
        <TabItemLabel>
          AWS CLI configurations
        </TabItemLabel>

        1. Open the CLI.

        2. Download the packages to create the client:

           ```go
           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
           ```

        3. [Configure the AWS CLI](/logs/tools/aws-cli.mdx).

        4. Create or open the client script file.

        5. Add the script to the file. The script will configure the client with the settings you specified for the [AWS CLI](/logs/tools/aws-cli.mdx#configure-aws-cli):

        ```go
        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)
        }
        ```
      </TabItem>

      <TabItem value="overriden-config">
        <TabItemLabel>
          Overridden AWS CLI configurations
        </TabItemLabel>

        1. Open the CLI.

        2. Download the packages to create the client:

           ```go
           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
           ```

        3. [Configure the AWS CLI](/logs/tools/aws-cli.mdx).

        4. Create or open the client script file.

        5. Add the script to the file. You can override the [AWS CLI](/logs/tools/aws-cli.mdx#configure-aws-cli) configurations in the script:

        ```go
        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](/logs/tools/aws-cli.mdx#issue-s3-key);
        * 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](/logs/tools/aws-cli.mdx#issue-s3-key);
        * optional: `region := "<pool>"` — override the [pool](/infrastructure/locations.mdx#pool). In the `<pool>` parameter, specify a pool, for example  `ru-9`;
        * `<log_endpoint>` — the URL for accessing the Logs service API. You can find the list of URLs in the [Logs](/api/urls/#logs) subsection of the [URL List](/api/urls/).
      </TabItem>

      <TabItem value="custom-config">
        <TabItemLabel>
          Custom configurations
        </TabItemLabel>

        1. Open the CLI.

        2. Download the packages to create the client:

           ```go
           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
           ```

        3. Create or open the client script file.

        4. Add the script to the file:

        ```go
        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](/logs/tools/aws-cli.mdx#issue-s3-key);
        * `<secret_key>` — the value of the **Secret key** field from the S3 key that you [issued to the user](/logs/tools/aws-cli.mdx#issue-s3-key);
        * `<pool>` — the [pool](/infrastructure/locations.mdx#pool) for generating the [API URL](/api/urls/) for the Logs service;
        * `<log_endpoint>` — the URL for accessing the Logs service API. You can find the list of URLs in the [Logs](/api/urls/#logs) subsection of the [URL List](/api/urls/).
      </TabItem>
    </Tabs>
  </TabItem>
</Tabs>

<Formbricks />
