Skip to content

Commit 54fab81

Browse files
authored
Merge branch 'main' into dependabot/npm_and_yarn/aws-cdk-ca6f6bb926
2 parents 2460f05 + 54d9be4 commit 54fab81

File tree

7 files changed

+43
-16
lines changed

7 files changed

+43
-16
lines changed

packages/parser/src/middleware/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ import type { ParserOptions, ParserOutput } from '../types/parser.js';
1212
* ```typescript
1313
* import { parser } from '@aws-lambda-powertools/parser/middleware';
1414
* import middy from '@middy/core';
15-
* import { sqsEnvelope } from '@aws-lambda-powertools/parser/envelopes/sqs;'
15+
* import { SqsEnvelope } from '@aws-lambda-powertools/parser/envelopes/sqs';
1616
*
17-
* const oderSchema = z.object({
17+
* const orderSchema = z.object({
1818
* id: z.number(),
1919
* description: z.string(),
2020
* quantity: z.number(),
2121
* });
2222
*
23-
* type Order = z.infer<typeof oderSchema>;
23+
* type Order = z.infer<typeof orderSchema>;
2424
*
2525
* export const handler = middy()
26-
* .use(parser({ schema: oderSchema, envelope: sqsEnvelope }))
26+
* .use(parser({ schema: orderSchema, envelope: SqsEnvelope }))
2727
* .handler(async (event) => {
2828
* // ^ event is inferred as Order[]
2929
* })

packages/tracer/tests/e2e/decorator.test.functionCode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export class LambdaFunction {
4444

4545
await this.methodNoResponse(event.invocation);
4646
await httpRequest({
47-
hostname: 'docs.powertools.aws.dev',
48-
path: '/lambda/typescript/latest/',
47+
hostname: 'docs.aws.amazon.com',
48+
path: '/powertools/typescript/latest/',
4949
});
5050

5151
const res = this.myMethod();

packages/tracer/tests/e2e/decorator.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('Tracer E2E tests, decorator instrumentation', () => {
7676
* 1. Lambda Context (AWS::Lambda)
7777
* 2. Lambda Function (AWS::Lambda::Function)
7878
* 4. DynamoDB (AWS::DynamoDB)
79-
* 4. Remote call (docs.powertools.aws.dev)
79+
* 4. Remote call (docs.aws.amazon.com)
8080
*/
8181
expectedSegmentsCount: 4,
8282
});
@@ -100,11 +100,11 @@ describe('Tracer E2E tests, decorator instrumentation', () => {
100100
expect(subsegments.size).toBe(3);
101101

102102
// Check remote call subsegment
103-
expect(subsegments.has('docs.powertools.aws.dev')).toBe(true);
104-
const httpSubsegment = subsegments.get('docs.powertools.aws.dev');
103+
expect(subsegments.has('docs.aws.amazon.com')).toBe(true);
104+
const httpSubsegment = subsegments.get('docs.aws.amazon.com');
105105
expect(httpSubsegment?.namespace).toBe('remote');
106106
expect(httpSubsegment?.http?.request?.url).toEqual(
107-
'https://docs.powertools.aws.dev/lambda/typescript/latest/'
107+
'https://docs.aws.amazon.com/powertools/typescript/latest/'
108108
);
109109
expect(httpSubsegment?.http?.request?.method).toBe('GET');
110110
expect(httpSubsegment?.http?.response?.status).toEqual(expect.any(Number));

packages/tracer/tests/e2e/manual.test.functionCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const handler = async (
3333
tracer.putMetadata(customMetadataKey, customMetadataValue);
3434

3535
try {
36-
await fetch('https://docs.powertools.aws.dev/lambda/typescript/latest/');
36+
await fetch('https://docs.aws.amazon.com/powertools/typescript/latest/');
3737

3838
const res = customResponseValue;
3939
if (event.throw) {

packages/tracer/tests/e2e/middy.test.functionCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const handler = middy(
3434
},
3535
})
3636
);
37-
await fetch('https://docs.powertools.aws.dev/lambda/typescript/latest/');
37+
await fetch('https://docs.aws.amazon.com/powertools/typescript/latest/');
3838

3939
if (event.throw) {
4040
throw new Error(customErrorMessage);

packages/tracer/tests/e2e/middy.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('Tracer E2E tests, middy instrumentation', () => {
7575
* 1. Lambda Context (AWS::Lambda)
7676
* 2. Lambda Function (AWS::Lambda::Function)
7777
* 4. DynamoDB (AWS::DynamoDB)
78-
* 4. Remote call (docs.powertools.aws.dev)
78+
* 4. Remote call (docs.aws.amazon.com)
7979
*/
8080
expectedSegmentsCount: 4,
8181
});
@@ -100,11 +100,11 @@ describe('Tracer E2E tests, middy instrumentation', () => {
100100
expect(subsegments.has('DynamoDB')).toBe(true);
101101

102102
// Check remote call subsegment
103-
expect(subsegments.has('docs.powertools.aws.dev')).toBe(true);
104-
const httpSubsegment = subsegments.get('docs.powertools.aws.dev');
103+
expect(subsegments.has('docs.aws.amazon.com')).toBe(true);
104+
const httpSubsegment = subsegments.get('docs.aws.amazon.com');
105105
expect(httpSubsegment?.namespace).toBe('remote');
106106
expect(httpSubsegment?.http?.request?.url).toEqual(
107-
'https://docs.powertools.aws.dev/lambda/typescript/latest/'
107+
'https://docs.aws.amazon.com/powertools/typescript/latest/'
108108
);
109109
expect(httpSubsegment?.http?.request?.method).toBe('GET');
110110
expect(httpSubsegment?.http?.response?.status).toEqual(expect.any(Number));

packages/tracer/tests/helpers/httpRequest.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { OutgoingHttpHeaders } from 'node:http';
12
import https, { type RequestOptions } from 'node:https';
23

34
/**
@@ -20,6 +21,32 @@ const httpRequest = (params: RequestOptions): Promise<unknown> =>
2021
params.timeout = 5000;
2122
}
2223

24+
// Ensure some common headers are present. Many sites (including AWS docs)
25+
// block requests that don't include a User-Agent or typical Accept header,
26+
// which is why the `fetch` call (which sets defaults) succeeds while a
27+
// bare https.request may receive a 403.
28+
const originalHeaders = (params.headers ?? {}) as OutgoingHttpHeaders;
29+
// Create a quick lowercase map of header names to detect presence case-insensitively
30+
const lowerMap = Object.keys(originalHeaders).reduce<
31+
Record<string, string>
32+
>((acc, k) => {
33+
acc[k.toLowerCase()] = k;
34+
return acc;
35+
}, {});
36+
37+
// Only add defaults when not present (case-insensitive)
38+
if (!lowerMap['user-agent']) {
39+
// prefer a Node/undici-like UA to match what fetch/undici would send
40+
(originalHeaders as Record<string, string>)['User-Agent'] =
41+
'node-fetch/1.0 (+https://github.com/node-fetch/node-fetch)';
42+
}
43+
if (!lowerMap.accept) {
44+
(originalHeaders as Record<string, string>).Accept =
45+
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
46+
}
47+
48+
params.headers = originalHeaders;
49+
2350
const req = https.request(params, (res) => {
2451
if (
2552
res.statusCode == null ||

0 commit comments

Comments
 (0)