使用你偏好的包管理器将 SDK 添加到你的项目。
npm install aws-cdkyarn add aws-cdkpnpm add aws-cdk以最简配置快速上手运行。
// Lambda@Edge functionexports.handler = async (event) => { const request = event.Records[0].cf.request if (request.uri.startsWith('/tracio/')) { request.origin = { custom: { domainName: 'edge.tracio.ai', protocol: 'https', } } } return request}包含错误处理、加载状态和高级配置的生产级模式。
// Lambda@Edge — origin-request functionexports.handler = async (event) => { const request = event.Records[0].cf.request if (!request.uri.startsWith('/tracio/')) { return request } // Rewrite the origin to your tracio.ai server request.uri = request.uri.replace(/^\/tracio/, '') request.origin = { custom: { domainName: process.env.TRACIO_ORIGIN || 'edge.tracio.ai', port: 443, protocol: 'https', sslProtocols: ['TLSv1.2'], path: '', readTimeout: 10, keepaliveTimeout: 5, }, } // Forward client IP for accurate geolocation request.headers['x-forwarded-for'] = [{ key: 'X-Forwarded-For', value: request.clientIp, }] // Set cache behavior: cache agent script, skip identification if (request.uri.includes('/agent')) { request.headers['cache-control'] = [{ key: 'Cache-Control', value: 'public, max-age=3600', }] } return request}用于初始化和配置 SDK 的所有可用选项。
publicKeystring来自仪表盘的公钥 — 可安全地随浏览器代码发布endpointstring用于代理路由部署的自定义端点 URL — 显式 URL 优先于 regionregionstring数据区域:us 或 eutimeoutMsnumber整个 getResult() 调用的超时时间(毫秒)linkedIdstring已登录用户在您系统内的账户 ID,用于关联共享同一设备的访问tagstring附加到识别请求上的自由格式标签,例如 checkout 或 logindebugboolean将脚本生命周期和网络活动输出到浏览器控制台scriptUrlstring完全覆盖 agent 脚本 URL — 用于自托管或 Subresource Integrity通过完整的 API 参考、webhook 配置和高级指南深入了解。