UNPKG

@qrvey/health-checker

Version:

![install size](https://packagephobia.com/badge?p=@qrvey/health-checker) ![coverage](https://img.shields.io/badge/unit_test_coverage-87%25-brightgreen)

45 lines 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.signAWSRequest = signAWSRequest; const credential_providers_1 = require("@aws-sdk/credential-providers"); const signature_v4_1 = require("@smithy/signature-v4"); const sha256_js_1 = require("@aws-crypto/sha256-js"); const protocol_http_1 = require("@smithy/protocol-http"); const constants_1 = require("../utils/constants"); async function signAWSRequest(url, method = 'GET', body, region = constants_1.DEFAULT_AWS_REGION, service = 'es') { try { const parsedUrl = new URL(url); const request = new protocol_http_1.HttpRequest({ method, protocol: parsedUrl.protocol, hostname: parsedUrl.hostname, port: parsedUrl.port ? Number(parsedUrl.port) : undefined, path: parsedUrl.pathname + parsedUrl.search, headers: { 'Content-Type': 'application/json', host: parsedUrl.hostname, }, body, }); // Get AWS credentials using fromNodeProviderChain // This automatically checks: // 1. Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN) // 2. ~/.aws/credentials file // 3. IAM roles (EC2 instance profile, ECS task role, etc.) // 4. AWS SSO const credentialsProvider = (0, credential_providers_1.fromNodeProviderChain)(); const credentials = await credentialsProvider(); const signer = new signature_v4_1.SignatureV4({ credentials, region, service, sha256: sha256_js_1.Sha256, }); const signedRequest = await signer.sign(request); return signedRequest.headers; } catch (error) { throw new Error(`Failed to sign AWS request: ${error instanceof Error ? error.message : 'Unknown error'}`); } } //# sourceMappingURL=awsSignature.js.map