Skip to content

create_scraper

create_scraper(
    scrape_configuration: ScrapeConfiguration,
    source: Source,
    destination: Destination,
    *,
    config_overrides: Optional[ampClientConfig] = None,
    alias: Optional[ScraperAlias] = None,
    role_configuration: Optional[RoleConfiguration] = None,
    client_token: Optional[IdempotencyToken] = None,
    tags: Optional[TagMap] = None,
    exporters: Optional[ExporterList] = None,
) -> CreateScraperResponse

Creates a scraper to collect metrics from Prometheus-compatible sources. The scraper sends the collected metrics to Amazon Managed Service for Prometheus workspaces or CloudWatch datasets. You can configure scrapers to collect metrics from Amazon EKS clusters, Amazon MSK clusters, or from VPC-based sources that support DNS-based service discovery. Scrapers are flexible. You can configure a scraper to control which metrics to collect, the frequency of collection, which transformations to apply to the metrics, and more.

An IAM role will be created for you that Amazon Managed Service for Prometheus uses to access the metrics in your source. You must configure this role with a policy that allows it to scrape metrics from your source. For Amazon EKS sources, see Configuring your Amazon EKS cluster in the Amazon Managed Service for Prometheus User Guide.

The scrapeConfiguration parameter contains the base-64 encoded YAML configuration for the scraper.

When creating a scraper, the service creates a Network Interface in each Availability Zone that are passed into CreateScraper through subnets. These network interfaces are used to connect to your source within the VPC for scraping metrics.

For more information about collectors, including what metrics are collected, and how to configure the scraper, see Using an Amazon Web Services managed collector in the Amazon Managed Service for Prometheus User Guide.

Parameters:

  • alias (Optional[ScraperAlias], default: None ) –

    (optional) An alias to associate with the scraper. This is for your use, and does not need to be unique.

  • scrape_configuration (ScrapeConfiguration) –

    The configuration file to use in the new scraper. For more information, see Scraper configuration in the Amazon Managed Service for Prometheus User Guide.

  • source (Source) –

    The Amazon EKS or Amazon Web Services cluster from which the scraper will collect metrics.

  • destination (Destination) –

    The destination where the scraper sends the collected metrics. Valid destinations are Amazon Managed Service for Prometheus workspaces and CloudWatch datasets.

  • role_configuration (Optional[RoleConfiguration], default: None ) –

    Use this structure to enable cross-account access, so that you can use a target account to access Prometheus metrics from source accounts.

  • client_token (Optional[IdempotencyToken], default: None ) –

    (Optional) A unique, case-sensitive identifier that you can provide to ensure the idempotency of the request.

  • tags (Optional[TagMap], default: None ) –

    (Optional) The list of tag keys and values to associate with the scraper.

  • exporters (Optional[ExporterList], default: None ) –

    The exporter configurations for the scraper. You can configure at most one Amazon OpenSearch Service domain. If you don't specify a value, the scraper is created without an exporter configuration.

Raises:

Examples:

CreateScraper with optional alias input, optional clientToken input, and one set of tags

>>> client.create_scraper(alias='alias', scrape_configuration={'configurationBlob': 'blob'}, source={'eksConfiguration': {'clusterArn': 'arn:aws:eks:us-west-2:123456789012:cluster/example', 'securityGroupIds': ['sg-abc123'], 'subnetIds': ['subnet-abc123']}}, destination={'ampConfiguration': {'workspaceArn': 'arn:aws:aps:us-west-2:123456789012:workspace/ws-ogh2u499-ce12-hg89-v6c7-123412341234'}}, client_token='token', tags={'exampleTag': 'exampleValue'})
CreateScraper with generic VPC config with mandatory securityGroupIds and subnetIds
>>> client.create_scraper(alias='alias', scrape_configuration={'configurationBlob': 'blob'}, source={'vpcConfiguration': {'securityGroupIds': ['sg-abc123'], 'subnetIds': ['subnet-abc123']}}, destination={'ampConfiguration': {'workspaceArn': 'arn:aws:aps:us-west-2:123456789012:workspace/ws-ogh2u499-ce12-hg89-v6c7-123412341234'}}, client_token='token', tags={'exampleTag': 'exampleValue'})
Source code in docs_src/capo_amp/_services/amp.py
def create_scraper(
    self,
    scrape_configuration: "capo_amp.types.scrape_configuration.ScrapeConfiguration",
    source: "capo_amp.types.source.Source",
    destination: "capo_amp.types.destination.Destination",
    *,
    config_overrides: Optional[ampClientConfig] = None,
    alias: Optional["capo_amp.types.scraper_alias.ScraperAlias"] = None,
    role_configuration: Optional[
        "capo_amp.types.role_configuration.RoleConfiguration"
    ] = None,
    client_token: Optional[
        "capo_amp.types.idempotency_token.IdempotencyToken"
    ] = None,
    tags: Optional["capo_amp.types.tag_map.TagMap"] = None,
    exporters: Optional["capo_amp.types.exporter_list.ExporterList"] = None,
) -> "capo_amp.types.create_scraper_response.CreateScraperResponse":
    """<p>Creates a scraper to collect metrics from Prometheus-compatible sources. The scraper sends the collected metrics to Amazon Managed Service for Prometheus workspaces or CloudWatch datasets. You can configure scrapers to collect metrics from Amazon EKS clusters, Amazon MSK clusters, or from VPC-based sources that support DNS-based service discovery. Scrapers are flexible. You can configure a scraper to control which metrics to collect, the frequency of collection, which transformations to apply to the metrics, and more.</p> <p>An IAM role will be created for you that Amazon Managed Service for Prometheus uses to access the metrics in your source. You must configure this role with a policy that allows it to scrape metrics from your source. For Amazon EKS sources, see <a href="https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-collector-how-to.html#AMP-collector-eks-setup">Configuring your Amazon EKS cluster</a> in the <i>Amazon Managed Service for Prometheus User Guide</i>.</p> <p>The <code>scrapeConfiguration</code> parameter contains the base-64 encoded YAML configuration for the scraper.</p> <p>When creating a scraper, the service creates a <code>Network Interface</code> in each <b>Availability Zone</b> that are passed into <code>CreateScraper</code> through subnets. These network interfaces are used to connect to your source within the VPC for scraping metrics.</p> <note> <p>For more information about collectors, including what metrics are collected, and how to configure the scraper, see <a href="https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-collector-how-to.html">Using an Amazon Web Services managed collector</a> in the <i>Amazon Managed Service for Prometheus User Guide</i>.</p> </note>

    Args:
        alias: <p>(optional) An alias to associate with the scraper. This is for your use, and does not need to be unique.</p>
        scrape_configuration: <p>The configuration file to use in the new scraper. For more information, see <a href="https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-collector-how-to.html#AMP-collector-configuration">Scraper configuration</a> in the <i>Amazon Managed Service for Prometheus User Guide</i>.</p>
        source: <p>The Amazon EKS or Amazon Web Services cluster from which the scraper will collect metrics.</p>
        destination: <p>The destination where the scraper sends the collected metrics. Valid destinations are Amazon Managed Service for Prometheus workspaces and CloudWatch datasets.</p>
        role_configuration: <p>Use this structure to enable cross-account access, so that you can use a target account to access Prometheus metrics from source accounts.</p>
        client_token: <p>(Optional) A unique, case-sensitive identifier that you can provide to ensure the idempotency of the request.</p>
        tags: <p>(Optional) The list of tag keys and values to associate with the scraper.</p>
        exporters: <p>The exporter configurations for the scraper. You can configure at most one Amazon OpenSearch Service domain. If you don't specify a value, the scraper is created without an exporter configuration.</p>

    Raises:
        capo_amp.errors.access_denied_exception.AccessDeniedException: <p>You do not have sufficient access to perform this action.</p>
        capo_amp.errors.conflict_exception.ConflictException: <p>The request would cause an inconsistent state.</p>
        capo_amp.errors.internal_server_exception.InternalServerException: <p>An unexpected error occurred during the processing of the request.</p>
        capo_amp.errors.resource_not_found_exception.ResourceNotFoundException: <p>The request references a resources that doesn't exist.</p>
        capo_amp.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>Completing the request would cause a service quota to be exceeded.</p>
        capo_amp.errors.throttling_exception.ThrottlingException: <p>The request was denied due to request throttling.</p>
        capo_amp.errors.validation_exception.ValidationException: <p>The input fails to satisfy the constraints specified by an Amazon Web Services service.</p>
        capo_amp.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        CreateScraper with optional alias input, optional clientToken input, and one set of tags

        >>> client.create_scraper(alias='alias', scrape_configuration={'configurationBlob': 'blob'}, source={'eksConfiguration': {'clusterArn': 'arn:aws:eks:us-west-2:123456789012:cluster/example', 'securityGroupIds': ['sg-abc123'], 'subnetIds': ['subnet-abc123']}}, destination={'ampConfiguration': {'workspaceArn': 'arn:aws:aps:us-west-2:123456789012:workspace/ws-ogh2u499-ce12-hg89-v6c7-123412341234'}}, client_token='token', tags={'exampleTag': 'exampleValue'})
        CreateScraper with generic VPC config with mandatory securityGroupIds and subnetIds

        >>> client.create_scraper(alias='alias', scrape_configuration={'configurationBlob': 'blob'}, source={'vpcConfiguration': {'securityGroupIds': ['sg-abc123'], 'subnetIds': ['subnet-abc123']}}, destination={'ampConfiguration': {'workspaceArn': 'arn:aws:aps:us-west-2:123456789012:workspace/ws-ogh2u499-ce12-hg89-v6c7-123412341234'}}, client_token='token', tags={'exampleTag': 'exampleValue'})
    """

    def _handler(
        req: "OperationRequest[capo_amp.types.create_scraper_request.CreateScraperRequest]",
    ) -> OperationResponse[
        "capo_amp.types.create_scraper_response.CreateScraperResponse"
    ]:
        import capo_amp._operations.amazon_prometheus_service.create_scraper

        output, http_response = (
            capo_amp._operations.amazon_prometheus_service.create_scraper.create_scraper(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateScraper")
    )
    input_: capo_amp.types.create_scraper_request.CreateScraperRequest = {
        "scrape_configuration": scrape_configuration,
        "source": source,
        "destination": destination,
    }
    if alias is not None:
        input_["alias"] = alias
    if role_configuration is not None:
        input_["role_configuration"] = role_configuration
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if tags is not None:
        input_["tags"] = tags
    if exporters is not None:
        input_["exporters"] = exporters

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output