How to Configure Grafana Agent AWS Request Signing
In the expansive and increasingly interconnected landscape of cloud-native infrastructure, robust monitoring and observability are not merely desirable features; they are foundational pillars for operational stability, performance optimization, and proactive problem resolution. As organizations continue to migrate and build applications within Amazon Web Services (AWS), the need for secure, authenticated communication between monitoring agents and various AWS services becomes paramount. Among the diverse tools available, Grafana Agent has emerged as a lightweight, efficient, and versatile telemetry collector, capable of gathering metrics, logs, and traces from a myriad of sources and forwarding them to chosen destinations, including those within the AWS ecosystem. However, interacting with AWS services securely mandates adherence to AWS's stringent authentication mechanisms, most notably AWS Signature Version 4 (SigV4). This comprehensive guide delves deep into the intricacies of configuring Grafana Agent to perform AWS request signing, ensuring that your observability data is transmitted with the highest levels of security and integrity.
The journey of collecting telemetry from your infrastructure and applications, often spanning across multiple AWS accounts, regions, and services, necessitates a clear understanding of how Grafana Agent can securely integrate with the native AWS authentication process. Without proper request signing, attempts by Grafana Agent to send data to services like Amazon S3 for archival, Amazon Kinesis Firehose for streaming logs, or even to discover resources via AWS apis like EC2, would be met with swift rejection, leading to critical blind spots in your monitoring strategy. This guide aims to demystify the process, walking you through the conceptual underpinnings of Grafana Agent and AWS SigV4, detailing the essential prerequisites, and providing practical, step-by-step configuration examples for both Grafana Agent's static and Flow modes.
Furthermore, beyond the direct secure interactions between agents and specific AWS services, the broader paradigm of api management and the role of an api gateway cannot be overstated in modern architectures. While Grafana Agent handles the secure transport of telemetry at the infrastructure level, a dedicated api gateway provides a critical control plane for managing, securing, and optimizing the flow of api calls across an entire enterprise, particularly relevant in today's AI-driven application landscape. We will explore how these concepts intertwine, highlighting the distinct yet complementary roles they play in building a resilient and secure operational environment. By the end of this extensive guide, you will possess the knowledge and practical expertise to confidently configure Grafana Agent for AWS request signing, thus fortifying your cloud observability stack and contributing to a more secure and efficient cloud operation.
Chapter 1: Understanding Grafana Agent and AWS Request Signing
The foundation of effectively configuring Grafana Agent for AWS request signing lies in a thorough understanding of both the agent's capabilities and the security mechanisms employed by AWS. This chapter will lay that groundwork, dissecting Grafana Agent's role in telemetry collection and elucidating the critical nature of AWS Signature Version 4 (SigV4) for secure interactions within the AWS ecosystem.
1.1 What is Grafana Agent?
Grafana Agent is an open-source, lightweight telemetry collector designed by Grafana Labs to efficiently gather observability data—metrics, logs, and traces—and forward it to various destinations, predominantly Grafana Cloud or self-hosted Grafana instances with their respective backends (Prometheus, Loki, Tempo). It acts as a universal agent, consolidating the functionalities that would traditionally require separate agents like Prometheus node_exporter, Promtail, and OpenTelemetry Collector. This consolidation significantly reduces resource consumption and simplifies deployment and management, making it an attractive choice for environments ranging from Kubernetes clusters to bare-metal servers and virtual machines.
At its core, Grafana Agent is highly configurable and offers two primary modes of operation: 1. Static Mode: This mode utilizes a single, monolithic configuration file (typically YAML) where users define scrape configurations, remote write endpoints, and other parameters in a similar fashion to Prometheus or Promtail. It's straightforward for simpler deployments and familiar to users accustomed to traditional Prometheus configurations. In static mode, specific exporter components or remote_write configurations are directly defined within this file. 2. Flow Mode: Introduced to provide more flexibility and a declarative, graph-based approach, Flow mode allows users to define a pipeline of components. Each component performs a specific task, such as scraping metrics, processing logs, or forwarding data. These components can be chained together, passing data between them like nodes in a directed acyclic graph. This modularity enables highly complex and customized telemetry pipelines, allowing for dynamic target discovery, sophisticated data processing, and conditional routing, all while maintaining a high degree of transparency in the data flow.
Grafana Agent’s versatility stems from its ability to integrate with a wide array of sources and destinations. For metrics, it speaks the Prometheus remote write protocol. For logs, it uses the Loki api or can transform logs for other targets. For traces, it supports OpenTelemetry and Jaeger formats. When deployed within AWS, Grafana Agent becomes an indispensable component of an observability stack, often needing to interact directly with AWS services for purposes like fetching instance metadata, sending metrics to CloudWatch or Kinesis Firehose, or archiving logs to S3. These interactions, inherently, require robust authentication and authorization mechanisms to prevent unauthorized access and maintain data integrity. The challenge then becomes how to empower Grafana Agent with the necessary credentials and mechanisms to securely communicate with these protected AWS resources, which is precisely where AWS request signing comes into play.
1.2 The Necessity of AWS Request Signing (SigV4)
AWS Signature Version 4 (SigV4) is the protocol for authenticating incoming requests to AWS apis. It's not just a simple username and password; instead, it's a cryptographic process that ensures both the identity of the requester and the integrity of the request itself. Every request made to an AWS service api must be signed using SigV4, unless it's a publically accessible resource (which is rare for data ingestion endpoints). This cryptographic signing mechanism is fundamental to AWS's security model, providing a robust layer of protection against various threats, including:
- Authentication: Verifying that the entity making the request is indeed who they claim to be, by proving possession of valid AWS credentials.
- Authorization: After authentication, AWS can then determine if the authenticated identity has the necessary permissions (via IAM policies) to perform the requested action on the specified resource.
- Integrity: Ensuring that the request has not been tampered with in transit. The signature is computed based on various parts of the request (HTTP method, URI, query parameters, headers, and the payload), meaning any alteration to these parts would invalidate the signature.
- Non-Repudiation: Providing a strong assurance that the request originated from a specific source, preventing the sender from falsely denying having sent the request.
The core components involved in SigV4 signing include:
- Access Key ID and Secret Access Key: These are the primary credentials that identify the AWS account and provide the secret used for signing. For temporary credentials, a Session Token is also required.
- Signing Key: A temporary key derived from the secret access key, specific to a date, AWS region, and service, used to sign the request.
- Canonical Request: A standardized representation of the HTTP request, carefully constructed from method, URI, query string, headers, and payload. This ensures that both the client and server compute the signature over the exact same data.
- String to Sign: A concatenation of the algorithm, request date, credential scope (date, region, service), and the hash of the canonical request.
- Signature: The final cryptographic hash, computed using the signing key and the string to sign, which is then included in the
Authorizationheader of the HTTP request.
Nearly all AWS services with api endpoints require SigV4 authentication. This includes, but is not limited to: * Amazon S3: For PutObject operations (e.g., archiving logs). * Amazon Kinesis Data Firehose: For PutRecordBatch (e.g., streaming logs or metrics). * Amazon CloudWatch Logs: For PutLogEvents. * AWS Security Token Service (STS): For AssumeRole operations to obtain temporary credentials. * AWS EC2 Metadata Service (IMDSv2): While not direct SigV4, IMDSv2 requires session tokens for enhanced security, often integrated with how agents obtain credentials.
For Grafana Agent, this means that any time it needs to interact with these services—be it to send collected data or to discover resources—it must construct and sign its HTTP requests according to the SigV4 protocol. Failing to do so will result in an Access Denied or SignatureDoesNotMatch error, effectively breaking your observability pipeline. Therefore, understanding and correctly configuring SigV4 is not just an option but a mandatory step for any Grafana Agent deployment operating within AWS.
1.3 The Challenge: Bridging Grafana Agent and AWS Security
The inherent challenge in securely integrating Grafana Agent with AWS services lies in translating Grafana Agent's configuration paradigms into the specific requirements of AWS SigV4. While Grafana Agent is designed to be highly flexible, it doesn't natively "speak" SigV4 without explicit configuration. The agent needs to be provided with the necessary credentials and instructions on how to use them to sign its outgoing HTTP requests for AWS endpoints.
Consider a scenario where Grafana Agent is deployed on an EC2 instance or within an EKS cluster. It might need to: 1. Export metrics: Send collected Prometheus metrics to an AWS-backed time series database, or perhaps push transformed metrics directly into Amazon Kinesis Firehose. 2. Export logs: Stream application logs collected by its Promtail-like capabilities to Amazon CloudWatch Logs, or archive them periodically to an S3 bucket. 3. Discover targets: Utilize AWS apis (like EC2 or EKS apis) to dynamically discover new scrape targets based on tags or other metadata.
In each of these scenarios, Grafana Agent initiates an HTTP request to an AWS service endpoint. Without SigV4, these requests are essentially anonymous and will be rejected. The agent's configuration must therefore specify:
- AWS Region: The specific AWS region where the target service resides (e.g.,
us-east-1). - AWS Service Name: The particular AWS service it's interacting with (e.g.,
s3,firehose,logs). This is crucial because the SigV4 signing process is service-specific. - Credentials: A mechanism to obtain and use AWS credentials (Access Key ID, Secret Access Key, and potentially a Session Token). This is arguably the most critical and sensitive part of the configuration, requiring careful consideration of security best practices.
- Signing Logic: An instruction to enable SigV4 signing for specific HTTP clients or remote write configurations.
Grafana Agent addresses this by incorporating aws_sigv4 configuration blocks within its http_client_config or directly within certain components (especially in Flow mode). These blocks allow you to define the region, service name, and how credentials should be obtained. The agent then internally handles the complex cryptographic process of generating the SigV4 signature for each outgoing request.
The core difficulty often arises from: * Credential Management: Ensuring that credentials are provided securely and follow the principle of least privilege. Hardcoding credentials is a significant security risk. * Correct Service Names and Regions: Mismatched service names or regions are common misconfigurations that lead to SignatureDoesNotMatch errors. * IAM Permissions: The IAM role or user associated with the credentials must have the correct Action and Resource permissions to perform the desired operations on the target AWS service.
This chapter has established the foundational knowledge necessary to approach Grafana Agent's AWS integration. The subsequent chapters will build upon this by detailing the prerequisites for secure configuration, followed by practical examples for both static and Flow modes, addressing these challenges head-on.
Chapter 2: Prerequisites for AWS Request Signing
Before diving into the specifics of Grafana Agent configuration, it is essential to ensure that the underlying AWS environment is prepared correctly. This involves setting up appropriate IAM roles and policies, understanding secure credential management, and confirming network connectivity. Neglecting these foundational steps can lead to frustrating authentication failures and security vulnerabilities.
2.1 AWS IAM Roles and Policies
AWS Identity and Access Management (IAM) is the cornerstone of security in AWS, allowing you to manage access to AWS services and resources securely. For Grafana Agent to successfully perform AWS request signing and interact with services, it must assume an identity with the necessary permissions. The principle of least privilege should always guide the creation of IAM roles and policies, granting only the permissions required to perform specific tasks.
1. Creating an IAM Role: The most secure and recommended method for granting permissions to Grafana Agent, especially when running on EC2 instances or within an EKS cluster, is through an IAM role. An IAM role is an AWS identity that you can create with specific permissions policies. It does not have standard long-term credentials (like passwords or access keys) associated with it. Instead, entities (like EC2 instances or Kubernetes service accounts) can temporarily assume the role to obtain temporary security credentials.
- Trust Policy: When creating an IAM role, you define a trust policy that specifies which entities are allowed to assume this role.
- For EC2 Instances: The trust policy would allow
ec2.amazonaws.comto assume the role. This enables EC2 instances to automatically obtain temporary credentials associated with the role assigned to their instance profile.json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "ec2.amazonaws.com" }, "Action": "sts:AssumeRole" } ] } - For EKS Service Accounts (IRSA): If Grafana Agent runs as a pod in EKS, you would use IAM Roles for Service Accounts (IRSA). The trust policy would allow the OIDC provider URL for your EKS cluster and the specific Kubernetes service account to assume the role. (More on IRSA in Chapter 5.1).
json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::<ACCOUNT_ID>:oidc-provider/oidc.eks.<REGION>.amazonaws.com/id/<OIDC_ID>" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { "oidc.eks.<REGION>.amazonaws.com/id/<OIDC_ID>:sub": "system:serviceaccount:<NAMESPACE>:<SERVICE_ACCOUNT_NAME>" } } } ] }
- For EC2 Instances: The trust policy would allow
2. Attaching Permissions Policies: Once the role is created, you attach permission policies that define what actions Grafana Agent can perform on specific AWS resources.
- Example Policy for Sending Logs to S3: If Grafana Agent needs to send logs to an S3 bucket, it requires
s3:PutObjectand potentiallys3:GetObjectAcl,s3:PutObjectAcl(if specific ACLs are needed, though bucket policy is generally preferred) on the target bucket.json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:PutObject", "s3:AbortMultipartUpload", "s3:ListMultipartUploadParts", "s3:ListBucketMultipartUploads" ], "Resource": [ "arn:aws:s3:::your-grafana-agent-logs-bucket/*", "arn:aws:s3:::your-grafana-agent-logs-bucket" ] }, { "Effect": "Allow", "Action": "s3:GetBucketLocation", "Resource": "arn:aws:s3:::your-grafana-agent-logs-bucket" } ] } - Example Policy for Sending Logs/Metrics to Kinesis Firehose: For streaming data to Kinesis Firehose,
firehose:PutRecordBatchis typically required.json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "firehose:PutRecord", "firehose:PutRecordBatch" ], "Resource": "arn:aws:firehose:<REGION>:<ACCOUNT_ID>:deliverystream/your-firehose-delivery-stream-name" } ] } - Example Policy for CloudWatch Logs: If pushing logs to CloudWatch Logs,
logs:CreateLogGroup,logs:CreateLogStream, andlogs:PutLogEventsare necessary.json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents" ], "Resource": "arn:aws:logs:<REGION>:<ACCOUNT_ID>:log-group:/aws/grafana-agent/*:log-stream:*" } ] }
Always review and tighten these policies to ensure they align perfectly with the minimal operational needs of Grafana Agent. Over-permissive policies are a significant security risk.
2.2 AWS Credentials Management
Securely providing AWS credentials to Grafana Agent is critical. Hardcoding credentials directly into configuration files or container images is highly discouraged due to the risk of exposure. AWS provides several secure methods for managing and distributing credentials, which Grafana Agent can leverage.
Here's a breakdown of common methods, ordered by general preference for security and manageability:
1. IAM Instance Profiles (for EC2 Instances): This is the recommended approach when running Grafana Agent on an EC2 instance. When you launch an EC2 instance, you can associate an IAM role with it via an instance profile. The instance profile acts as a container for the IAM role. Grafana Agent, running on that EC2 instance, can automatically retrieve temporary security credentials from the EC2 instance metadata service (IMDSv2 recommended). These credentials are short-lived and automatically rotated by AWS. This method removes the need to explicitly manage credentials on the instance itself.
2. IAM Roles for Service Accounts (IRSA - for EKS/Kubernetes): For Grafana Agent deployed as a pod within an Amazon EKS cluster, IRSA is the most secure method. It allows you to associate an IAM role directly with a Kubernetes service account. Pods configured to use that service account can then assume the specified IAM role, obtaining temporary AWS credentials. This is analogous to instance profiles for EC2 but designed for the Kubernetes environment, preventing all pods in a node from inheriting the same role.
3. Environment Variables: You can set AWS credentials as environment variables in the operating system where Grafana Agent is running: * AWS_ACCESS_KEY_ID * AWS_SECRET_ACCESS_KEY * AWS_SESSION_TOKEN (if using temporary credentials) This method is suitable for testing or development environments, or in CI/CD pipelines where credentials can be securely injected. However, for production deployments, directly setting these variables on a server is less secure than IAM roles, as they might be discoverable by other processes if not handled carefully. In containerized environments, these can be passed as secrets, but IRSA is generally superior for EKS.
4. Shared Credential File (~/.aws/credentials): AWS CLI and SDKs can read credentials from a shared file, typically located at ~/.aws/credentials on Linux/macOS or %USERPROFILE%\.aws\credentials on Windows. This file contains profiles with aws_access_key_id and aws_secret_access_key. While convenient for local development, it's generally not recommended for production servers due to the static nature of the credentials and the risk of the file being compromised.
5. AWS Secrets Manager or other Secret Management Systems: For more advanced scenarios or heterogeneous environments, you could store AWS credentials in AWS Secrets Manager (or HashiCorp Vault, Kubernetes Secrets) and configure Grafana Agent (or its surrounding environment) to retrieve these secrets at runtime. This adds complexity but centralizes secret management and enables robust rotation policies.
Comparison of Credential Management Methods:
| Method | Security Level | Ease of Management | Recommended Use Case | Pros | Cons |
|---|---|---|---|---|---|
| IAM Instance Profiles | High | High | EC2 instances | No explicit credential management on instance; auto-rotated credentials | Specific to EC2 instances; requires instance launch configuration. |
| IAM Roles for Service Accounts (IRSA) | High | High | EKS/Kubernetes pods | Fine-grained permissions per pod; auto-rotated credentials; no host creds | Requires EKS OIDC provider setup; Kubernetes knowledge needed. |
| Environment Variables | Medium | Medium | Development, CI/CD, simple container deployments (with secure injection) | Relatively easy to set; no filesystem access required. | Can be exposed if not handled as secrets; static credentials without rotation. |
| Shared Credential File | Low | Medium | Local development, single-server non-critical applications (rarely for prod) | Familiar to AWS CLI users; simple setup. | Static, long-lived credentials; risk of file compromise; not scalable for many instances. |
| Secrets Manager Integration | Very High | Medium/High | Complex, multi-account, or hybrid environments requiring centralized secret management | Centralized, dynamic secret management; robust rotation. | Adds complexity; requires agent to retrieve secrets; potential for rate limiting on API calls. |
When configuring Grafana Agent, the default AWS SDK credential chain is often used, meaning it will attempt to find credentials in a specific order (environment variables, shared credentials file, IMDSv2). Leveraging IAM roles (via Instance Profiles or IRSA) allows Grafana Agent to inherit credentials without any sensitive information directly present in its configuration or runtime environment, thus aligning with best security practices.
2.3 Network Connectivity and Security Groups
Beyond authentication, ensuring that Grafana Agent can actually reach the AWS service endpoints is a fundamental prerequisite. Network connectivity issues can be just as disruptive as authentication failures.
1. VPC and Subnet Configuration: Grafana Agent typically resides within a Virtual Private Cloud (VPC). Ensure that the subnet where Grafana Agent is deployed has a route to the internet (via an Internet Gateway for public subnets or a NAT Gateway for private subnets) if it needs to reach public AWS service endpoints. For enhanced security and lower latency, consider using VPC Endpoints (AWS PrivateLink) for services like S3, Kinesis Firehose, or CloudWatch Logs. VPC Endpoints allow resources within your VPC to connect to supported AWS services privately, without traversing the public internet.
2. Security Groups: Security groups act as virtual firewalls for your instances or network interfaces. For Grafana Agent to send data to AWS services, the security group attached to the EC2 instance or EKS worker nodes (or the EKS pod's security group if using Pod-level security groups) must allow outbound HTTPS (port 443) traffic to the relevant AWS service endpoints.
- Outbound Rules: Configure outbound rules to allow traffic on port 443. The destination can be
0.0.0.0/0if connecting to public endpoints, but a more restrictive approach is to use the IP address ranges for AWS service endpoints in your specific region. AWS publishes these IP ranges in JSON format, which can be updated dynamically. For VPC Endpoints, the security group attached to the endpoint will control inbound access to the endpoint itself, while the security group on the Grafana Agent will control outbound access to the endpoint's private IP. - Inbound Rules (for internal discovery/scrape targets): If Grafana Agent is also configured to scrape internal applications or expose its own metrics endpoint, ensure appropriate inbound rules are in place for those interactions.
3. Network Access Control Lists (NACLs): While security groups operate at the instance/ENI level, NACLs operate at the subnet level and provide another layer of network filtering. Review NACL rules to ensure they are not inadvertently blocking outbound traffic on port 443 from the Grafana Agent's subnet. NACLs are stateless, so both inbound and outbound rules must explicitly allow the traffic.
4. DNS Resolution: Grafana Agent needs to resolve the AWS service endpoints (e.g., s3.us-east-1.amazonaws.com, firehose.us-east-1.amazonaws.com). Ensure that your VPC's DNS resolution (provided by Amazon's Route 53 resolver or custom DNS servers) is correctly configured and functioning. If using VPC Endpoints, ensure DNS resolution is correctly configured to resolve to the private IP addresses of the endpoint.
By diligently addressing these prerequisites, you create a robust and secure environment for Grafana Agent to operate within AWS, minimizing the potential for runtime failures related to authentication or network connectivity. With this foundation established, we can now proceed to the practical configuration of Grafana Agent itself.
Chapter 3: Configuring Grafana Agent for AWS Request Signing (Static Mode)
In Grafana Agent's static mode, configuration is typically managed through a single YAML file, mirroring the structure often seen in Prometheus and Promtail. This mode relies on explicit definitions for data sources, scrape jobs, and remote write targets. When integrating with AWS services, the aws_sigv4 configuration block becomes crucial for instructing Grafana Agent to sign its HTTP requests. This chapter will detail the general principles and provide practical examples for common AWS integration scenarios.
3.1 General Principles of AWS Request Signing in Static Mode
Grafana Agent's static mode supports AWS Signature Version 4 (SigV4) authentication by embedding specific aws_sigv4 configuration within http_client_config blocks. These http_client_config blocks are commonly found in sections defining remote write endpoints, S3 storage configurations, or other HTTP-based interactions. The presence of this configuration block tells Grafana Agent to automatically sign outgoing HTTP requests to the specified region and service using the provided or discovered AWS credentials.
The typical parameters within an aws_sigv4 block include:
region(string): The AWS region where the target service resides (e.g.,us-east-1,eu-west-2). This is a mandatory parameter as the SigV4 signature is region-specific.service_name(string): The canonical name of the AWS service the request is being sent to (e.g.,s3,firehose,logs,sts,ec2). This is also mandatory and critical for correct signing. A mismatch here is a common cause ofSignatureDoesNotMatcherrors.access_key_id(string): (Optional, but required if not using IAM roles/environment variables) The AWS access key ID. Should ideally be avoided by using IAM roles.secret_access_key(string): (Optional, but required if not using IAM roles/environment variables) The AWS secret access key. Highly sensitive and should never be hardcoded.role_arn(string): (Optional) The ARN of an IAM role to assume. If specified, Grafana Agent will usests:AssumeRoleto obtain temporary credentials before signing requests. This is useful for cross-account access or when wanting to explicitly assume a different role than the one assigned to the host.profile(string): (Optional) The name of a profile in the shared AWS credentials file (~/.aws/credentials) to use. Less recommended for production.
Important Note on Credential Precedence: When access_key_id and secret_access_key are not explicitly provided within the Grafana Agent configuration, it will fall back to the standard AWS SDK credential chain. This chain typically searches for credentials in the following order: 1. Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN). 2. Shared credentials file (~/.aws/credentials). 3. IAM role associated with the EC2 instance profile or EKS service account (via IMDSv2).
Therefore, the most secure approach is to configure an appropriate IAM role for your EC2 instance or EKS service account (as discussed in Chapter 2.2), and then simply specify region and service_name within the aws_sigv4 block, letting Grafana Agent automatically discover the temporary credentials.
Here's a table summarizing common AWS services and their respective service_name values for SigV4:
| AWS Service | service_name Value |
Primary Use Case for Grafana Agent |
|---|---|---|
| Amazon S3 | s3 |
Storing logs, metrics backups |
| Amazon Kinesis Firehose | firehose |
Streaming logs, metrics |
| Amazon CloudWatch Logs | logs |
Sending application logs |
| AWS Security Token Service | sts |
Assuming IAM roles (role_arn) |
| Amazon EC2 | ec2 |
Discovering EC2 instances |
| Amazon CloudWatch | monitoring |
Reading CloudWatch metrics |
| Amazon EventBridge | events |
Sending events |
Understanding these principles is vital before proceeding to concrete configuration examples.
3.2 Example 1: Sending Logs to AWS S3 via Promtail (within Grafana Agent)
Grafana Agent can act as a Promtail replacement, collecting logs from files and forwarding them to various destinations. A common requirement is to archive these logs to an S3 bucket for long-term storage, compliance, or further analysis. Here's how to configure Grafana Agent (static mode) to send logs to S3 with AWS request signing.
First, ensure you have an S3 bucket created (e.g., grafana-agent-logs-archive-bucket) and an IAM role attached to your Grafana Agent's host with s3:PutObject permissions for that bucket, as detailed in Chapter 2.1.
# grafana-agent.yaml for static mode
server:
http_listen_port: 12345
grpc_listen_port: 12346
logs:
configs:
- name: application_logs
scrape_configs:
- job_name: app_logs
static_configs:
- targets:
- localhost
labels:
job: application_logs
__path__: /var/log/app/*.log # Path to your application logs
target_config:
sync_period: 10s
positions:
filename: /tmp/positions.yaml # State file for tracking log read positions
# S3 storage configuration for logs
clients:
- url: https://s3.<YOUR_AWS_REGION>.amazonaws.com/<YOUR_S3_BUCKET_NAME>/loki/api/v1/push
tenant_id: single-tenant # Or specify your tenant ID if using Grafana Cloud multi-tenant
batchwait: 5s
batchsize: 1048576 # 1MB
# AWS SigV4 configuration for S3
aws_sigv4:
region: <YOUR_AWS_REGION> # e.g., us-east-1
service_name: s3
# If using IAM role on EC2 instance or IRSA on EKS,
# you don't need to specify access_key_id or secret_access_key here.
# Agent will automatically pick up credentials from the environment or IMDS.
# If you need to assume a different role, specify role_arn:
# role_arn: arn:aws:iam::<ACCOUNT_ID>:role/YourCrossAccountRole
Explanation of the S3 Log Configuration:
logs.configs: This section defines log collection pipelines.scrape_configs: Similar to Promtail, this defines how logs are scraped.__path__specifies the log file paths.url: This is the critical part for S3. Although it looks like a Lokiapiendpoint, for S3 storage, Loki (or Grafana Agent emulating it) is typically configured to use an S3 backend. Theurlhere acts more as a conceptual endpoint for the client, and the actual S3 interaction is handled by theaws_sigv4section. The path structure/loki/api/v1/pushis often used when Loki is configured with an S3 object store.- Important Correction: The
urlshould actually point to a Loki instance (or Grafana Cloud Loki endpoint) that itself is configured to use S3 for storage. Grafana Agent as a Promtail replacement directly pushes to a Loki-compatible endpoint. If the goal is to directly store logs in S3 as raw files or in a format consumable by Athena/other tools, a differentexportercomponent or configuration might be needed (e.g., specificloki.write.s3in Flow mode, or a separate log shipper). - Revisiting Direct S3 Storage for Raw Logs (more typical scenario for direct agent-S3 interactions): If the intention is to send raw log files directly to S3 without passing through a Loki instance, Grafana Agent's static mode
remote_writefor Loki-compatible storage does not directly support arbitrary S3PutObjectoperations for raw logs. Instead, it expects a Loki-like endpoint. For directly sending files to S3, one would typically use tools like Filebeat with S3 output, or write a customexporter. - Revised Example (more accurate for what
aws_sigv4inhttp_client_configtypically enables for Promtail/Loki clients): Theaws_sigv4block inside a Loki client is typically for authenticating with a Loki instance that itself runs in AWS and might require SigV4 if protected by anapi gatewayor AWS authentication proxy, or for internal AWS service calls made by Loki. However, if the intent is for Grafana Agent to use S3 as a direct data sink, this usually implies a specificexporterfor S3. - Let's assume a more conventional
remote_writescenario where a Loki-compatible endpoint is secured by an AWSapi gatewayor similar mechanism requiring SigV4.
- Important Correction: The
clients: This is where destinations for collected logs are configured.Revised Example 1 (Focus on a general remote_write to a SigV4 protected endpoint): If you were sending metrics to an endpoint (e.g., Mimir or Cortex running on AWS with IAM auth) that requires SigV4, or if a custom api gateway in front of your Loki instance required it: ```yaml
grafana-agent.yaml for static mode - general remote_write with SigV4
server: http_listen_port: 12345 grpc_listen_port: 12346metrics: configs: - name: default remote_write: - url: https://your-aws-protected-mimir-endpoint.com/api/v1/push name: aws-mimir-remote-write send_start_timestamp: true # http_client_config is where aws_sigv4 applies http_client_config: aws_sigv4: region:# e.g., us-east-1 service_name: execute-api # If your endpoint is behind AWS API Gateway # For other custom services, service_name might be 'aoss' for OpenSearch Serverless # or if a custom endpoint, it might require a specific service name or none # and rely solely on role_arn for STS. # If using IAM role on EC2 instance or IRSA on EKS, credentials will be picked up automatically. # role_arn: arn:aws:iam:::role/YourCustomMimirAccessRole scrape_configs: - job_name: agent_internal static_configs: - targets: [localhost:12345] metrics_path: /metrics
Loki client example for a Loki instance protected by an AWS API Gateway
logs: configs: - name: application_logs scrape_configs: - job_name: app_logs static_configs: - targets: - localhost labels: job: application_logs path: /var/log/app/*.log
clients:
- url: https://your-aws-protected-loki-endpoint.com/loki/api/v1/push
tenant_id: single-tenant
batchwait: 5s
batchsize: 1048576
# AWS SigV4 configuration for the Loki endpoint, if protected by API Gateway or similar
aws_sigv4:
region: <YOUR_AWS_REGION>
service_name: execute-api # Typical for AWS API Gateway endpoints
# Or other appropriate service_name if the endpoint is a different AWS service
`` This refined example correctly demonstrates howaws_sigv4is nested withinhttp_client_configfor remote write endpoints or directly within Lokiclientswhen the *destination endpoint itself* requires AWS SigV4 authentication, often when it's fronted by AWSAPI Gateway`.
3.3 Example 2: Sending Metrics to AWS Kinesis Firehose
Streaming metrics to AWS Kinesis Firehose is a robust way to ingest large volumes of time-series data into S3, Redshift, Splunk, or other destinations. Grafana Agent can be configured to use remote_write to send metrics to a Firehose delivery stream, using SigV4 for authentication.
First, set up a Kinesis Firehose delivery stream in your AWS account and configure an IAM role for Grafana Agent with firehose:PutRecordBatch permissions for that stream.
# grafana-agent.yaml for static mode - Kinesis Firehose metrics
server:
http_listen_port: 12345
grpc_listen_port: 12346
metrics:
configs:
- name: default
scrape_configs:
- job_name: node_exporter
static_configs:
- targets: ['localhost:9100'] # Assuming node_exporter is running
metric_relabel_configs:
- source_labels: [__name__]
regex: "node_.*" # Example: only send node_exporter metrics
remote_write:
- url: https://firehose.<YOUR_AWS_REGION>.amazonaws.com/
name: kinesis_firehose_metrics
send_start_timestamp: true
# The Kinesis Firehose API endpoint uses a specific service_name
# http_client_config applies aws_sigv4
http_client_config:
aws_sigv4:
region: <YOUR_AWS_REGION> # e.g., us-east-1
service_name: firehose # This is the crucial service name for Kinesis Firehose
# Credentials will be auto-discovered from IAM role/environment
# role_arn: arn:aws:iam::<ACCOUNT_ID>:role/YourFirehoseAccessRole
- name: agent_internal_metrics
scrape_configs:
- job_name: agent_internal
static_configs:
- targets: ['localhost:12345']
metrics_path: /metrics
Explanation of Kinesis Firehose Metrics Configuration:
metrics.configs: Defines metrics collection and forwarding.scrape_configs: Standard Prometheus-like scrape configuration. Here, we're scrapingnode_exportermetrics.metric_relabel_configscan be used to filter or modify metrics before sending.remote_write:url: This is the base URL for the Kinesis Firehoseapiendpoint. Note that the actual path forPutRecordBatchis implicitly handled by the SigV4 signing process and the client library.http_client_config: This block contains theaws_sigv4configuration.region: The AWS region where your Firehose delivery stream is located.service_name: firehose: This is the correct and essential service name for interacting with Kinesis Firehose.
- Credential Handling: As before, Grafana Agent will attempt to retrieve credentials via the standard AWS SDK chain. Ensure your Grafana Agent's execution environment has an IAM role with
firehose:PutRecordBatchpermissions on the specified delivery stream.
This setup ensures that all metrics scraped by Grafana Agent will be signed with SigV4 before being sent to the Kinesis Firehose delivery stream, providing secure and authenticated data ingestion.
3.4 Example 3: Consuming Metrics from AWS SQS/CloudWatch (e.g., via a Prometheus Exporter)
While Grafana Agent can directly push data, it also needs to be able to pull data from AWS services for certain scenarios. This often involves using a Prometheus-style exporter that fetches data from AWS services (like CloudWatch or SQS) and exposes it in a Prometheus-compatible format for Grafana Agent to scrape. These exporters themselves need AWS credentials and SigV4 to interact with AWS.
Let's consider an example where you use sqs_exporter or cloudwatch_exporter (separate applications, not part of Grafana Agent itself) which Grafana Agent then scrapes. The aws_sigv4 configuration within Grafana Agent is generally for its outgoing connections. However, if Grafana Agent itself needs to discover targets or perform other AWS API calls as part of its scrape process, it can also use aws_sigv4 in sd_configs (service discovery configurations).
Let's illustrate how aws_sigv4 would be used if Grafana Agent were to discover targets via an AWS API (e.g., ec2_sd_config):
# grafana-agent.yaml for static mode - AWS EC2 Service Discovery
server:
http_listen_port: 12345
grpc_listen_port: 12346
metrics:
configs:
- name: default
scrape_configs:
- job_name: ec2_instances
# Using ec2_sd_config to discover EC2 instances
ec2_sd_configs:
- region: <YOUR_AWS_REGION> # e.g., us-east-1
port: 9100 # Default node_exporter port
# Role for EC2 discovery (if different from remote_write)
# role_arn: arn:aws:iam::<ACCOUNT_ID>:role/YourEC2DiscoveryRole
# http_client_config here is for the EC2 API calls made by Grafana Agent
http_client_config:
aws_sigv4:
region: <YOUR_AWS_REGION>
service_name: ec2 # Service name for EC2 API
# Credentials auto-discovered from IAM role/environment
relabel_configs:
- source_labels: [__meta_ec2_instance_id]
target_label: instance_id
- source_labels: [__meta_ec2_tag_Name]
target_label: instance_name
# ... other relabeling based on EC2 metadata
remote_write:
- url: https://your-prometheus-remote-write-endpoint.com/api/v1/write
name: main_remote_write
send_start_timestamp: true
Explanation of EC2 Service Discovery with SigV4:
ec2_sd_configs: This block tells Grafana Agent to use the AWS EC2apito discover scrape targets.http_client_configwithinec2_sd_configs: This is crucial. Theaws_sigv4block nested here is specifically for authenticating the API calls Grafana Agent makes to the EC2 service itself (e.g.,DescribeInstancesAPI call).region: The region where your EC2 instances reside.service_name: ec2: The correct service name for the EC2 API.
- Permissions for Discovery: The IAM role for Grafana Agent must have
ec2:DescribeInstancespermission (and potentiallyec2:DescribeTagsif filtering by tags) for this to work.
This example illustrates that aws_sigv4 is not only for data export but also for internal AWS API interactions that Grafana Agent might perform for service discovery or other operational tasks. Each instance of http_client_config that needs AWS authentication can include its own aws_sigv4 block, ensuring specific credentials and service names are used for distinct AWS interactions. This granular control is vital for maintaining security and operational clarity in complex cloud environments.
APIPark is a high-performance AI gateway that allows you to securely access the most comprehensive LLM APIs globally on the APIPark platform, including OpenAI, Anthropic, Mistral, Llama2, Google Gemini, and more.Try APIPark now! 👇👇👇
Chapter 4: Configuring Grafana Agent Flow for AWS Request Signing
Grafana Agent Flow mode, with its declarative, graph-based configuration, offers a more flexible and powerful way to define telemetry pipelines compared to static mode. It uses a component-based approach where each component has inputs and outputs, allowing for complex data transformations and routing. AWS request signing in Flow mode is handled similarly to static mode, but with distinct component-specific configurations and the introduction of helper components for managing AWS credentials.
4.1 Understanding Grafana Agent Flow and Components
Grafana Agent Flow configuration is expressed in a CUE-like language, defining a series of interconnected components. Each component instance has a unique label (e.g., loki.source.aws_firehose.my_logs), and its output fields can be referenced as inputs by other components. This makes it highly modular and readable, especially for intricate pipelines.
Key components that commonly interact with AWS services include:
loki.source.aws_firehose: Collects logs from an AWS Kinesis Firehose delivery stream.prometheus.remote_write: Sends Prometheus metrics to a remote endpoint.discovery.aws.ec2,discovery.aws.s3,discovery.aws.autoscaling: Components for discovering various AWS resources as Prometheus scrape targets.aws.credentials: A dedicated helper component to manage and centralize AWS credential acquisition.
The power of Flow mode lies in its ability to dynamically manage multiple data streams, apply complex processing logic, and route data to different destinations, all within a single agent instance. This flexibility extends to how AWS request signing is configured, allowing for more granular control and reusability of credential configurations.
4.2 Authentication in Flow Components
In Flow mode, AWS authentication is typically configured in one of two ways:
- Directly within Component Definitions: Many components that interact with AWS services have a nested
awsblock (orauthblock withsigv4settings) whereregion,service_name,access_key_id,secret_access_key, androle_arncan be specified. This is similar to theaws_sigv4block in static mode'shttp_client_config. - Using
aws.credentialsHelper Component: For better reusability and centralized credential management, theaws.credentialscomponent can be used. This component encapsulates the logic for acquiring AWS credentials (from environment variables, instance profiles, or explicit keys/roles) and exposes these credentials as an output, which other AWS-aware components can then consume. This is the recommended approach for more complex Flow configurations, as it avoids duplicating credential information across multiple components.
The aws.credentials component is particularly powerful because it can be configured to assume a specific IAM role (role_arn) or to use explicit access_key_id and secret_access_key if absolutely necessary. When other components reference the output of an aws.credentials component, they automatically inherit the authentication context, including SigV4 signing.
Let's delve into examples to illustrate these concepts.
4.3 Example 1: Collecting Logs from AWS Kinesis Firehose
Collecting logs from Kinesis Firehose is a common pattern for centralizing application logs. The loki.source.aws_firehose component in Flow mode is specifically designed for this.
First, ensure you have a Kinesis Firehose delivery stream configured to receive logs and an IAM role for Grafana Agent with firehose:DescribeDeliveryStream, firehose:GetRecords, and potentially logs:CreateLogGroup, logs:CreateLogStream if Firehose itself is writing to CloudWatch Logs (though Grafana Agent usually pulls directly from the Firehose stream). The IAM role needs to be assumable by your EC2 instance or EKS service account.
# grafana-agent-flow.river for collecting logs from Kinesis Firehose
# 1. Define AWS credentials using aws.credentials component
# This component will automatically discover credentials if run on EC2 with an IAM role
# or via IRSA in EKS.
aws.credentials "default" {
# If you need to assume a specific role, uncomment and provide the ARN
# role_arn = "arn:aws:iam::<ACCOUNT_ID>:role/YourFirehoseReaderRole"
}
# 2. Collect logs from Kinesis Firehose
loki.source.aws_firehose "my_app_logs" {
delivery_stream_name = "your-firehose-delivery-stream-name"
region = "<YOUR_AWS_REGION>" # e.g., us-east-1
# Reference the credentials output from the aws.credentials component
credentials {
access_key_id = aws.credentials.default.access_key_id
secret_access_key = aws.credentials.default.secret_access_key
token = aws.credentials.default.token
}
# Labels to add to the collected logs
labels {
job = "firehose_logs"
env = "production"
}
# Output to a Loki writer component
forward_to = [loki.write.default.receiver]
}
# 3. Write logs to a Loki instance (e.g., Grafana Cloud Loki or self-hosted Loki)
loki.write "default" {
endpoint {
url = "https://your-loki-endpoint.com/loki/api/v1/push"
# If the Loki endpoint itself requires AWS SigV4 (e.g., fronted by AWS API Gateway)
# you would add an aws_sigv4 block here, potentially using another aws.credentials component
# for that specific endpoint's authentication.
}
}
Explanation of Kinesis Firehose Log Collection:
aws.credentials "default": This component is configured without explicit keys, meaning it will attempt to use the AWS SDK default credential chain (IAM instance profile, environment variables, etc.). Ifrole_arnis specified, it willsts:AssumeRole.loki.source.aws_firehose "my_app_logs":delivery_stream_nameandregionidentify the Firehose stream.credentialsblock: This is whereloki.source.aws_firehoseaccepts the credentials. By referencingaws.credentials.default.access_key_id, etc., we ensure that the component uses the credentials acquired by theaws.credentialscomponent. Theloki.source.aws_firehosecomponent inherently understands how to use these credentials to sign its API calls to the Firehose service.forward_to: Directs the collected logs to theloki.write.default.receivercomponent.
loki.write "default": This component is responsible for sending the logs to your Loki instance. Itsendpoint.urldefines the destination.
This modular approach significantly enhances clarity and reusability, especially when multiple components need to interact with different AWS services or assume different roles.
4.4 Example 2: Discovering Targets with discovery.aws
Grafana Agent can leverage AWS service discovery components to dynamically find and scrape targets, such as EC2 instances or ECS tasks. This is crucial for environments with fluctuating workloads and auto-scaling groups.
# grafana-agent-flow.river for EC2 service discovery
# 1. Define AWS credentials for discovery
aws.credentials "discovery_creds" {
# This role should have ec2:DescribeInstances permissions
# role_arn = "arn:aws:iam::<ACCOUNT_ID>:role/YourEC2DiscoveryRole"
}
# 2. Discover EC2 instances
discovery.aws.ec2 "ec2_targets" {
region = "<YOUR_AWS_REGION>"
# Reference the discovery credentials
credentials {
access_key_id = aws.credentials.discovery_creds.access_key_id
secret_access_key = aws.credentials.discovery_creds.secret_access_key
token = aws.credentials.discovery_creds.token
}
# You can filter instances by tags, states, etc.
# filters = [
# {
# name = "tag:Name"
# values = ["my-app-server*"]
# },
# {
# name = "instance-state-name"
# values = ["running"]
# }
# ]
}
# 3. Relabel discovered targets and specify scrape configurations
prometheus.relabel "relabel_ec2" {
targets = discovery.aws.ec2.ec2_targets.targets
# Add instance_id and instance_name labels from EC2 metadata
rule {
source_labels = ["__meta_ec2_instance_id"]
target_label = "instance_id"
}
rule {
source_labels = ["__meta_ec2_tag_Name"]
target_label = "instance_name"
}
# ... other relabeling rules
}
# 4. Scrape the discovered targets
prometheus.scrape "ec2_scrape" {
targets = prometheus.relabel.relabel_ec2.output
forward_to = [prometheus.remote_write.default.receiver]
job_name = "ec2_instances"
# Default scrape port, e.g., 9100 for node_exporter
metrics_path = "/techblog/en/metrics"
scheme = "http"
}
# 5. Write metrics to a remote endpoint
prometheus.remote_write "default" {
endpoint {
url = "https://your-metrics-endpoint.com/api/v1/write"
# If this endpoint requires AWS SigV4, configure it here:
# aws_sigv4 {
# region = "<YOUR_AWS_REGION>"
# service_name = "execute-api" # or appropriate service
# credentials {
# access_key_id = aws.credentials.default.access_key_id
# secret_access_key = aws.credentials.default.secret_access_key
# token = aws.credentials.default.token
# }
# }
}
}
Explanation of EC2 Service Discovery:
aws.credentials "discovery_creds": This component provides the credentials for thediscovery.aws.ec2component. The associated IAM role needs permissions likeec2:DescribeInstances.discovery.aws.ec2 "ec2_targets": This component makes AWS API calls to the EC2 service to list instances. Thecredentialsblock referencesaws.credentials.discovery_creds, ensuring theDescribeInstancesAPI call is signed with SigV4 using those credentials.prometheus.relabel "relabel_ec2": Processes the targets discovered bydiscovery.aws.ec2, adding useful labels from EC2 metadata.prometheus.scrape "ec2_scrape": Scrapes metrics from the relabeled targets.prometheus.remote_write "default": Forwards the scraped metrics to a remote storage. Note that if this remote storage (e.g., Mimir, Cortex) is also secured by an AWSapi gatewayor requires SigV4, you would configureaws_sigv4directly within itsendpointblock, potentially using anotheraws.credentialscomponent if distinct credentials are needed.
This example highlights the flexibility of Flow mode in building complex, dynamic monitoring pipelines, with aws.credentials acting as a central point for managing AWS authentication for various components.
4.5 Example 3: Writing Metrics to AWS-compatible Endpoints (e.g., Mimir on EKS)
When sending metrics to a remote endpoint that is hosted within AWS and perhaps secured by AWS-native authentication mechanisms, the prometheus.remote_write component can utilize SigV4. A common scenario is sending metrics to a Grafana Mimir or Cortex instance deployed on AWS EKS, where access to the remote_write endpoint might be protected by an AWS api gateway or IAM authentication, requiring SigV4.
# grafana-agent-flow.river for remote_write to an AWS-compatible endpoint
# 1. Define AWS credentials for remote write
aws.credentials "remote_write_creds" {
# This role should have permissions to invoke the target endpoint,
# e.g., execute-api:Invoke on the API Gateway associated with Mimir.
# role_arn = "arn:aws:iam::<ACCOUNT_ID>:role/YourMimirWriterRole"
}
# 2. Scrape internal agent metrics
prometheus.scrape "agent_metrics" {
targets = [{"__address__" = "localhost:12345", "job" = "grafana-agent"}]
forward_to = [prometheus.remote_write.mimir.receiver]
}
# 3. Scrape node_exporter metrics
prometheus.scrape "node_metrics" {
targets = [{"__address__" = "localhost:9100", "job" = "node_exporter"}]
forward_to = [prometheus.remote_write.mimir.receiver]
}
# 4. Write metrics to a Mimir instance on EKS protected by AWS API Gateway
prometheus.remote_write "mimir" {
endpoint {
url = "https://your-mimir-ingress.apigw.<YOUR_AWS_REGION>.amazonaws.com/api/v1/write"
# Enable AWS SigV4 for this endpoint
aws_sigv4 {
region = "<YOUR_AWS_REGION>"
service_name = "execute-api" # This is often the service name for AWS API Gateway
# Credentials for signing requests to the API Gateway
credentials {
access_key_id = aws.credentials.remote_write_creds.access_key_id
secret_access_key = aws.credentials.remote_write_creds.secret_access_key
token = aws.credentials.remote_write_creds.token
}
}
}
}
# Other components like logs, traces can be added here
Explanation of Remote Write to AWS-compatible Endpoint:
aws.credentials "remote_write_creds": This component provides the credentials specifically for authenticating with the Mimir remote write endpoint. The associated IAM role needs permissions to invoke the targetapi gatewayendpoint.prometheus.scrape "agent_metrics"andprometheus.scrape "node_metrics": These components collect metrics from various sources.prometheus.remote_write "mimir":endpoint.url: This is the URL of your Mimir instance, potentially fronted by an AWSapi gatewaywith IAM authentication. The URL structure often reflects an API Gateway custom domain or execution endpoint.aws_sigv4block: Nested within theendpointblock, this configures SigV4 signing for theremote_writerequests.region: The region where your API Gateway and Mimir instance are deployed.service_name: execute-api: This is the standard service name for invoking AWS API Gateway endpoints. If Mimir were directly exposed via, say, OpenSearch Serverless (AOSS), theservice_namewould beaoss. It's crucial to identify the correct AWS service that is protecting your target endpoint.credentialsblock: Referencesaws.credentials.remote_write_credsto obtain the necessary credentials for signing.
This example demonstrates how Flow mode, with its explicit credential management and component-level aws_sigv4 configuration, provides a flexible and secure way to interact with various AWS services, ensuring that every outgoing API call is properly authenticated and authorized. The distinction between the aws.credentials component for credential acquisition and the aws_sigv4 block for actual request signing within a component's endpoint configuration is a powerful paradigm in Grafana Agent Flow.
Chapter 5: Advanced Scenarios and Best Practices
Having covered the fundamental configurations for Grafana Agent AWS request signing in both static and Flow modes, it's crucial to explore more advanced scenarios and universal best practices that can further enhance security, efficiency, and reliability in a production AWS environment.
5.1 IAM Roles for Service Accounts (IRSA) in EKS
For Grafana Agent deployments within Amazon Elastic Kubernetes Service (EKS) clusters, IAM Roles for Service Accounts (IRSA) is the gold standard for credential management. IRSA allows you to associate an IAM role with a Kubernetes service account. Any pod configured to use that service account automatically assumes the associated IAM role and obtains temporary AWS credentials (via a projected web identity token). This mechanism offers several advantages over other methods:
- Fine-grained Permissions: You can assign distinct IAM roles to different service accounts, meaning different pods within the same EKS node can have different AWS permissions. This adheres strictly to the principle of least privilege.
- No Long-Lived Credentials: Pods never directly hold long-term AWS access keys or secret keys. They only receive short-lived, automatically rotated session tokens, significantly reducing the attack surface.
- Enhanced Security: It eliminates the need for node-level IAM instance profiles to grant broad permissions to all pods on a node, preventing potential privilege escalation if a pod is compromised.
- Simplified Management: Credentials are automatically managed by AWS and Kubernetes, reducing operational overhead.
Configuring IRSA for Grafana Agent:
- Enable OIDC Provider for EKS Cluster: Your EKS cluster must have an IAM OIDC provider. If not already enabled, you can do so via the AWS CLI or Console. This allows IAM to trust identities from your Kubernetes cluster.
bash aws eks update-cluster --name your-cluster-name --associate-oidc-provider --region <YOUR_AWS_REGION> - Create an IAM Role with a Trust Policy for the Service Account: Create an IAM role with the necessary permissions for Grafana Agent (e.g.,
s3:PutObject,firehose:PutRecordBatch,ec2:DescribeInstances). The trust policy for this role must explicitly allow your EKS cluster's OIDC provider and the specific Kubernetes service account to assume it.json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::<ACCOUNT_ID>:oidc-provider/oidc.eks.<REGION>.amazonaws.com/id/<OIDC_PROVIDER_ID>" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { "oidc.eks.<REGION>.amazonaws.com/id/<OIDC_PROVIDER_ID>:sub": "system:serviceaccount:<K8S_NAMESPACE>:<K8S_SERVICE_ACCOUNT_NAME>" } } } ] } - Attach the IAM Role to the Kubernetes Service Account: Annotate your Kubernetes service account with the ARN of the IAM role.
yaml apiVersion: v1 kind: ServiceAccount metadata: name: grafana-agent-service-account namespace: monitoring annotations: eks.amazonaws.com/role-arn: arn:aws:iam::<ACCOUNT_ID>:role/YourGrafanaAgentIAMRole - Configure Grafana Agent Deployment to Use the Service Account: Ensure your Grafana Agent
Deploymentmanifest specifies theserviceAccountName.yaml apiVersion: apps/v1 kind: Deployment metadata: name: grafana-agent namespace: monitoring spec: template: spec: serviceAccountName: grafana-agent-service-account containers: - name: agent image: grafana/agent:latest args: ["-config.file=/etc/agent/agent.yaml"] # For static mode # For Flow mode: -config.file=/etc/agent/agent.river
When configured this way, Grafana Agent running in the pod will automatically find and use the temporary credentials associated with its service account for all AWS API calls requiring SigV4, without any explicit access_key_id or secret_access_key in its configuration.
5.2 Cross-Account AWS Access
In larger organizations, it's common for Grafana Agent to run in one AWS account (e.g., a "monitoring" account) but need to send telemetry to services or discover resources in another AWS account (e.g., "application" or "log" accounts). This is achieved through IAM cross-account role assumption.
The process involves two main steps:
- Permissions to perform the desired actions on its resources (e.g.,
s3:PutObjecton a specific S3 bucket). - A trust policy that allows the IAM role from the source (monitoring) account to assume it. ```json
- IAM Role: The IAM role assigned to Grafana Agent in the source account (e.g.,
GrafanaAgentMonitoringRole) must havests:AssumeRolepermission on theCrossAccountGrafanaAgentRolein the target account.json # Policy for GrafanaAgentMonitoringRole in SOURCE account { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "sts:AssumeRole", "Resource": "arn:aws:iam::<TARGET_ACCOUNT_ID>:role/CrossAccountGrafanaAgentRole" } ] } - Grafana Agent Configuration: Within Grafana Agent's
aws_sigv4block (static mode) oraws.credentialscomponent (Flow mode), specify therole_arnof the role in the target account.
Configure Grafana Agent's Role/Configuration in the Source Account:Static Mode Example: ```yaml
...
remote_write: - url: https://firehose.us-west-2.amazonaws.com/ http_client_config: aws_sigv4: region: us-west-2 service_name: firehose role_arn: arn:aws:iam:::role/CrossAccountGrafanaAgentRole # Assume this role ```Flow Mode Example: ```hcl aws.credentials "cross_account_firehose" { role_arn = "arn:aws:iam:::role/CrossAccountGrafanaAgentRole" }prometheus.remote_write "target_firehose" { endpoint { url = "https://firehose.us-west-2.amazonaws.com/" aws_sigv4 { region = "us-west-2" service_name = "firehose" credentials { access_key_id = aws.credentials.cross_account_firehose.access_key_id secret_access_key = aws.credentials.cross_account_firehose.secret_access_key token = aws.credentials.cross_account_firehose.token } } } } `` Grafana Agent will first use its own credentials (from theGrafanaAgentMonitoringRole) to callsts:AssumeRoleon theCrossAccountGrafanaAgentRole`, obtain temporary credentials, and then use those temporary credentials to sign requests to the target Firehose stream. This is a secure and scalable method for managing permissions across multiple AWS accounts.
Configure the Target Account's Role: In the target AWS account (where the service like S3 or Firehose resides), create an IAM role (e.g., CrossAccountGrafanaAgentRole) that has:
Trust Policy for CrossAccountGrafanaAgentRole in TARGET account
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam:::role/GrafanaAgentMonitoringRole" }, "Action": "sts:AssumeRole", "Condition": {} } ] } ```
5.3 Regional Considerations and Endpoints
AWS services are region-specific, and their API endpoints reflect this. The region parameter in aws_sigv4 configuration is not just a hint; it's a critical part of the SigV4 signing process. The signature calculation uses the specified region to ensure authenticity.
- Consistency: Always ensure the
regionconfigured in Grafana Agent matches the region where the target AWS service (S3 bucket, Kinesis Firehose stream, CloudWatch Logs group) is actually deployed. - Service Endpoints: While many AWS service endpoints follow a predictable pattern (e.g.,
service.region.amazonaws.com), some services or specific features might have unique endpoints. For example, S3 has a legacy virtual host style and a path-style endpoint, plus a globals3-accelerateendpoint. Always refer to the AWS documentation for the exact service endpoint URL if you encounter connectivity issues. - VPC Endpoints: If you are using VPC Endpoints (PrivateLink) to connect to AWS services privately, your Grafana Agent should resolve the service endpoint to its private IP address within your VPC. While the
regioninaws_sigv4remains important for the signing context, the DNS resolution ensures traffic stays within the AWS network.
5.4 Security Best Practices for Credentials
Beyond the technical configurations, adopting a strong security posture for credential management is paramount:
- Principle of Least Privilege: Grant Grafana Agent (via its IAM role) only the minimal permissions required to perform its specific tasks. For example, if it only needs to write logs to an S3 bucket, it should only have
s3:PutObjecton that bucket, nots3:DeleteObjectors3:*on all buckets. - Avoid Hardcoding: Never hardcode
access_key_idandsecret_access_keydirectly in configuration files, scripts, or container images. This is a severe security risk. - Utilize Temporary Credentials: Prioritize mechanisms that provide temporary, short-lived credentials, such as IAM roles for EC2 instance profiles or IRSA for EKS. These credentials are automatically rotated and have a limited lifespan, reducing the impact of a potential compromise.
- Secret Management Systems: For explicit
access_key_idandsecret_access_key(if absolutely unavoidable, e.g., for non-AWS hosts accessing AWS services), use dedicated secret management solutions like AWS Secrets Manager, HashiCorp Vault, or Kubernetes Secrets. Retrieve these secrets at runtime, injecting them as environment variables or mounting them as files, rather than embedding them directly. - Regular Credential Rotation: Implement policies for regularly rotating long-lived static credentials, if they must be used.
- Audit and Monitor: Regularly audit IAM policies and roles for unintended permissions. Use AWS CloudTrail to monitor
sts:AssumeRolecalls and other API activities to detect suspicious credential usage.
5.5 Monitoring and Troubleshooting
Even with the most meticulous configuration, issues can arise. Effective monitoring and troubleshooting are essential:
- Grafana Agent Internal Metrics: Grafana Agent exposes its own metrics endpoint (typically
/metricson its HTTP listen port). Scrape these metrics to monitor its health, scrape job status, remote write queue length, and errors. Look for metrics likeagent_remote_write_queue_appended_samples_total,agent_remote_write_queue_drops_total,agent_loki_write_requests_failed_totalto identify issues with data forwarding. - Grafana Agent Logs: Configure Grafana Agent's logging level (e.g.,
info,debug) to capture detailed operational logs. Errors related to AWS request signing (e.g.,SignatureDoesNotMatch,AccessDenied,NoCredentialProviderserrors) will appear in these logs.SignatureDoesNotMatch: Indicates an issue with the signature itself. Common causes: incorrectregion, incorrectservice_name, credentials mismatch, time skew between agent and AWS.AccessDenied: The request was correctly signed and authenticated, but the IAM role/user does not have the necessary permissions. Review IAM policies in CloudTrail.NoCredentialProviders: Grafana Agent could not find any AWS credentials. Check environment variables, shared credentials file, and IAM instance profile/IRSA configuration.
- AWS CloudTrail: CloudTrail records all AWS API calls made to your account. This is an invaluable tool for troubleshooting
AccessDeniedorSignatureDoesNotMatcherrors. You can see the exact API call, the identity that made it (or attempted to), and the error message returned by AWS. This helps verify if the request even reached AWS and what permission it failed on. - Network Diagnostics: Use tools like
curl,telnet, orpingfrom the Grafana Agent host to verify network connectivity to AWS service endpoints. If using VPC Endpoints, ensure DNS resolution correctly points to the private IPs. - Time Synchronization (NTP): SigV4 is highly sensitive to time discrepancies. Ensure that the host running Grafana Agent is synchronized with an accurate time source (e.g., NTP). A significant time skew between the agent and AWS servers can lead to
SignatureDoesNotMatcherrors.
By combining thorough configuration with robust monitoring and a systematic troubleshooting approach, you can maintain a highly reliable and secure Grafana Agent deployment interacting seamlessly with your AWS services.
Chapter 6: The Broader Context: API Management and Gateways
While the precise configuration of Grafana Agent for AWS request signing is critical for securing specific machine-to-service interactions, it's essential to place this within the broader context of modern api management and the crucial role of an api gateway. The cloud-native landscape, especially with the proliferation of microservices and the advent of AI apis, demands a holistic approach to managing how applications consume and expose functionality.
6.1 The Role of an API Gateway
An api gateway serves as a single entry point for all client requests to an application's backend services, effectively acting as a reverse proxy. It sits between client applications (web, mobile, other microservices) and the collection of backend services. Its primary purpose is to simplify, secure, and optimize api interactions, abstracting away the complexity of the underlying microservices architecture.
Consider a distributed application composed of dozens or hundreds of microservices. Without an api gateway, client applications would need to know the specific endpoints, authentication mechanisms, and data formats for each individual service they wish to consume. This leads to tightly coupled architectures, increased client-side complexity, and fragmented security policies.
An api gateway addresses these challenges by providing a centralized control plane for:
- Authentication and Authorization: Offloading authentication (e.g., OAuth2, JWT validation, API keys, AWS SigV4) from backend services. The
gatewayvalidates requests and often passes context (e.g., user ID, scope) to the backend. - Traffic Management: Routing requests to the appropriate backend service, load balancing across multiple instances, and enforcing rate limiting to prevent abuse or service degradation.
- Request/Response Transformation: Modifying request headers, query parameters, or even entire payloads before forwarding them to backend services. Similarly, responses can be aggregated or transformed before being sent back to the client.
- API Versioning: Managing different versions of
apis, allowing clients to consume older versions while new versions are being developed or rolled out. - Monitoring and Logging: Centralizing request logging, collecting metrics on
apiusage, latency, and error rates, providing a single pane of glass forapiperformance. - Security: Acting as a first line of defense with Web Application Firewall (WAF) integration, DDoS protection, and IP whitelisting.
AWS API Gateway is a prime example of a managed api gateway service that integrates deeply with other AWS services, providing secure, scalable, and fully managed api endpoints. It can integrate with AWS Lambda, EC2, or any publicly addressable endpoint, offering various authentication methods including IAM (which would leverage SigV4).
6.2 How API Gateways Enhance Security Beyond SigV4
While AWS SigV4 is crucial for authenticating direct calls to native AWS services, an api gateway extends security posture across the entire application landscape, providing a more comprehensive and flexible security layer.
Beyond just request signing, api gateways can enforce:
- Advanced Authentication Schemes: Support for OpenID Connect (OIDC), OAuth 2.0, SAML, and custom authorizers (e.g., Lambda functions) allows for flexible integration with various identity providers and complex authorization logic. This is particularly important for human users or external partner applications, where AWS SigV4 might not be the most suitable authentication method.
- Threat Protection: Integration with Web Application Firewalls (WAF) to protect against common web exploits (SQL injection, cross-site scripting), bot protection, and DDoS mitigation.
- Rate Limiting and Throttling: Preventing
apiabuse and ensuring fair usage by limiting the number of requests clients can make within a given timeframe. - Data Masking and Redaction: Sensitive data within requests or responses can be masked or redacted at the
gatewaylevel before reaching backend services or being logged, enhancing data privacy and compliance. - Mutual TLS (mTLS): Enforcing two-way authentication where both the client and the server verify each other's certificates, adding another strong layer of security for critical
apis. - Centralized Policy Enforcement: Security policies (e.g., encryption requirements, header validation) can be defined and enforced uniformly across all
apis, reducing the risk of misconfigurations in individual backend services.
An api gateway acts as a crucial enforcement point, ensuring that all traffic conforms to security policies before it ever reaches valuable backend resources, including potentially sensitive AI models or critical business apis.
6.3 Managing Complex API Ecosystems with API Gateways
The growth of microservices, serverless functions, and externally consumed apis has led to increasingly complex api ecosystems. An api gateway is indispensable for managing this complexity by:
- Simplifying Developer Experience: Developers consume a single, well-documented
apiinterface provided by thegateway, rather than needing to understand the intricacies of each backend service. This accelerates development and reduces integration errors. - Facilitating Service Evolution: Backend services can be independently scaled, updated, or even replaced without impacting clients, as long as the
apicontract exposed by thegatewayremains consistent. - Enabling Monolith to Microservices Transition: An
api gatewaycan gradually expose functionality from a decomposing monolith as new microservices are created, providing a seamless transition for clients. - Supporting Multi-Cloud and Hybrid Environments: A well-designed
gatewaycan abstract backend services running in different cloud providers or on-premises, presenting a unifiedapisurface. - Providing Analytics and Observability: Centralized logging and metrics from the
gatewayoffer a comprehensive view ofapiusage patterns, performance trends, and error rates, which are crucial for business insights and operational health.
This centralization of control and visibility is particularly vital in the era of AI. As organizations integrate more AI models—whether proprietary, open-source, or third-party—into their applications, the need for a robust gateway that can manage these AI apis, standardize their invocation, track costs, and enforce security policies becomes paramount.
6.4 Introducing APIPark: A Comprehensive AI Gateway & API Management Platform
While configuring AWS request signing directly within agents like Grafana Agent is essential for point-to-point secure communication with AWS services, the broader landscape of modern api management often involves a dedicated api gateway. For organizations dealing with a proliferation of apis, especially in the rapidly evolving AI space, a specialized solution can greatly streamline operations and enhance security. This is where platforms like APIPark come into play.
APIPark stands out as an open-source AI gateway and api management platform, designed to simplify the integration, management, and deployment of both AI and REST services. Unlike general-purpose api gateways, APIPark is specifically tailored to address the unique challenges of AI apis while providing comprehensive api lifecycle management capabilities.
How APIPark Complements Your AWS Security Strategy:
Imagine a scenario where your Grafana Agent securely collects metrics and logs using AWS SigV4 and sends them to AWS services. Now, consider your application that consumes multiple AI models (e.g., for sentiment analysis, translation, image recognition) and other internal REST apis. Managing authentication, rate limiting, and versioning for each of these apis individually can be a nightmare. APIPark acts as a unified gateway to centralize these concerns.
Key features of APIPark that highlight its value in a secure and efficient api ecosystem:
- Quick Integration of 100+ AI Models: APIPark provides a unified management system for a vast array of AI models, handling authentication and cost tracking centrally. This means your application doesn't need to manage distinct authentication for each AI
api. - Unified API Format for AI Invocation: It standardizes the request data format across different AI models. This crucial feature ensures that changes in underlying AI models or prompts do not break your applications or microservices, significantly simplifying AI usage and reducing maintenance costs. This kind of abstraction is a core benefit of a well-implemented
gateway. - Prompt Encapsulation into REST API: Users can combine AI models with custom prompts to quickly create new, specialized
apis (e.g., a "summarize text"api). This allows developers to easily build AI-powered features without deep AI expertise. - End-to-End API Lifecycle Management: From design and publication to invocation and decommissioning, APIPark assists with managing the entire lifecycle of APIs. It helps regulate
apimanagement processes, manages traffic forwarding, load balancing, and versioning of publishedapis, offering the comprehensive features expected from anapi gateway. - API Service Sharing within Teams: The platform centralizes the display of all
apiservices, making it easy for different departments and teams to discover and use requiredapis securely. - Independent API and Access Permissions for Each Tenant: APIPark enables the creation of multiple teams (tenants) with independent applications, data, user configurations, and security policies, while sharing underlying infrastructure. This improves resource utilization and provides robust multi-tenancy.
- API Resource Access Requires Approval: With subscription approval features, callers must subscribe to an
apiand await administrator approval, preventing unauthorizedapicalls and potential data breaches. This is a crucial security control for sensitiveapis. - Performance Rivaling Nginx: APIPark is engineered for high performance, capable of over 20,000 TPS with modest hardware, supporting cluster deployment for large-scale traffic. This performance is vital for handling high-volume AI and REST
apitraffic. - Detailed API Call Logging and Powerful Data Analysis: Comprehensive logging of every
apicall allows for quick troubleshooting, while data analysis of historical call data helps businesses with preventive maintenance and understanding long-term trends. These observability features complement the infrastructure-level telemetry collected by Grafana Agent.
APIPark, being an open-source solution by Eolink, provides a robust gateway that addresses the challenges of modern api management, particularly for AI services. While Grafana Agent meticulously handles secure data transfer to AWS services using SigV4, APIPark offers a strategic layer of control for your entire api landscape, ensuring that your application's interactions with its backend services and AI models are equally secure, efficient, and well-managed. Integrating such a platform into your architecture provides a unified approach to api governance, elevating security and operational efficiency across the board.
Conclusion
Securing your cloud-native observability stack within AWS is a multifaceted endeavor, and the ability of Grafana Agent to perform AWS request signing using Signature Version 4 (SigV4) is a critical component of that security posture. Throughout this extensive guide, we have explored the foundational principles of Grafana Agent's operation, the absolute necessity of AWS SigV4 for authenticated interactions with AWS services, and the crucial prerequisites that must be in place before embarking on configuration. From setting up appropriate IAM roles with the principle of least privilege to meticulously managing credentials through robust mechanisms like IAM instance profiles and IRSA for EKS, each step reinforces the security of your data pipeline.
We delved into practical, detailed configuration examples for both Grafana Agent's static and Flow modes, demonstrating how aws_sigv4 blocks and aws.credentials components enable the agent to securely send logs to S3-backed Loki endpoints, stream metrics to Kinesis Firehose, and dynamically discover targets via AWS APIs like EC2. These configurations are not merely technical directives; they are blueprints for ensuring the integrity and confidentiality of your valuable telemetry data as it traverses the AWS ecosystem. Furthermore, we examined advanced scenarios such as cross-account access, highlighted the importance of regional consistency, and reinforced a suite of security best practices for credential management. The chapter on troubleshooting provided actionable insights for diagnosing and resolving common issues, ensuring your monitoring capabilities remain uninterrupted.
Beyond the granular specifics of agent-to-service communication, we broadened our perspective to encompass the strategic role of an api gateway in managing the increasing complexity of modern application architectures. An api gateway serves as an indispensable control plane, offering centralized authentication, traffic management, and security enforcement for all api interactions, including those with diverse AI models and microservices. We introduced APIPark, an open-source AI gateway and api management platform, as a powerful example of how such a solution complements individual agent configurations. APIPark streamlines the integration and lifecycle management of AI and REST services, standardizing api invocation, enforcing granular access controls, and providing robust performance and analytics—ultimately creating a more secure, efficient, and governable api ecosystem.
In summary, mastering the configuration of Grafana Agent for AWS request signing is a non-negotiable skill for anyone operating within the AWS cloud. It guarantees that the data fueling your observability platforms is transmitted securely and reliably. When integrated into a comprehensive strategy that includes a capable api gateway for managing your broader api landscape, you build an infrastructure that is not only robust and scalable but also fortified against the evolving threats of the digital age. This layered approach to security, from agent-level authentication to gateway-level API governance, is the hallmark of resilient and forward-thinking cloud operations.
Frequently Asked Questions (FAQs)
1. What is AWS Signature Version 4 (SigV4) and why is it important for Grafana Agent?
AWS Signature Version 4 (SigV4) is a cryptographic protocol used by AWS to authenticate incoming requests to its services and ensure their integrity. It verifies the identity of the requester and confirms that the request has not been tampered with. For Grafana Agent, SigV4 is crucial because any direct interaction with AWS services (like sending logs to S3, metrics to Kinesis Firehose, or performing service discovery via EC2 APIs) requires these requests to be cryptographically signed. Without proper SigV4 configuration, AWS will reject Grafana Agent's requests, leading to failed data ingestion and monitoring blind spots.
2. What are the most secure ways to provide AWS credentials to Grafana Agent?
The most secure and recommended methods for providing AWS credentials to Grafana Agent involve using temporary credentials that are automatically managed by AWS: 1. IAM Instance Profiles: For Grafana Agent running on EC2 instances, assign an IAM role to the instance via an instance profile. Grafana Agent automatically retrieves temporary credentials from the EC2 instance metadata service. 2. IAM Roles for Service Accounts (IRSA): For Grafana Agent deployed in Amazon EKS, use IRSA to associate an IAM role directly with a Kubernetes service account. Pods using this service account obtain temporary credentials, ensuring fine-grained permissions. Avoid hardcoding access_key_id and secret_access_key directly in configuration files.
3. Can Grafana Agent assume an IAM role in a different AWS account for cross-account access?
Yes, Grafana Agent can assume an IAM role in a different AWS account to access resources across accounts. This is achieved by configuring the IAM role in the target account to trust the IAM role of the source account (where Grafana Agent runs). Grafana Agent's IAM role in the source account then needs sts:AssumeRole permission on the target account's role. In Grafana Agent's aws_sigv4 configuration or aws.credentials component, you specify the role_arn of the role in the target account. Grafana Agent will use its own credentials to assume this role and then use the temporary credentials obtained to sign requests to the target account's services.
4. What is the difference between region and service_name in Grafana Agent's aws_sigv4 configuration?
Both region and service_name are mandatory and critical for correct AWS SigV4 signing: * region: Specifies the AWS geographical region where the target AWS service is deployed (e.g., us-east-1, eu-west-2). The SigV4 signature is cryptographically bound to the specified region. * service_name: Specifies the canonical name of the AWS service the request is intended for (e.g., s3 for Amazon S3, firehose for Kinesis Firehose, ec2 for Amazon EC2 API, execute-api for AWS API Gateway). This name is also part of the signature calculation, ensuring the request is valid for that specific service. Incorrect service_name is a common cause of SignatureDoesNotMatch errors.
5. How does an API Gateway, like APIPark, relate to Grafana Agent's AWS request signing?
Grafana Agent's AWS request signing focuses on securing direct, machine-to-service communication within the AWS ecosystem for observability data. An api gateway, such as APIPark, operates at a higher architectural level, acting as a central entry point for all client requests to your application's backend services, including AI models and REST APIs. While Grafana Agent ensures secure data transport, an api gateway provides comprehensive API management: * It centralizes authentication, authorization (beyond just SigV4, handling OAuth2, JWTs, etc.), traffic management, and security policies for your entire API ecosystem. * APIPark, specifically, is tailored to manage AI APIs, unifying their invocation format, encapsulating prompts into REST APIs, and providing end-to-end API lifecycle management. In essence, Grafana Agent handles the secure "plumbing" for observability data, while an api gateway like APIPark manages the secure and efficient exposure and consumption of your application's business and AI functionalities. They are complementary layers in a robust cloud architecture.
🚀You can securely and efficiently call the OpenAI API on APIPark in just two steps:
Step 1: Deploy the APIPark AI gateway in 5 minutes.
APIPark is developed based on Golang, offering strong product performance and low development and maintenance costs. You can deploy APIPark with a single command line.
curl -sSO https://download.apipark.com/install/quick-start.sh; bash quick-start.sh

In my experience, you can see the successful deployment interface within 5 to 10 minutes. Then, you can log in to APIPark using your account.

Step 2: Call the OpenAI API.

