Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslint_dictionary.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"anonymize",
"ansi",
"anthropic",
"apis",
"apns",
"apollo",
"appleid",
Expand Down Expand Up @@ -42,6 +43,7 @@
"cron",
"ctor",
"darwin",
"datasources",
"datastore",
"datasync",
"debounce",
Expand Down Expand Up @@ -147,6 +149,8 @@
"pathname",
"pipelined",
"pnpm",
"poller",
"pollers",
"positionals",
"posix",
"postgres",
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@aws-sdk/client-amplify": "^3.750.0",
"@aws-sdk/client-cloudformation": "^3.750.0",
"@aws-sdk/client-lambda": "^3.750.0",
"@aws-sdk/client-cloudwatch-logs": "^3.750.0",
"@aws-sdk/client-s3": "^3.750.0",
"@aws-sdk/client-sts": "^3.750.0",
"@aws-sdk/credential-provider-ini": "^3.750.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { getLogGroupName } from './log_group_extractor.js';

void describe('getLogGroupName function', () => {
void it('returns correct log group name for Lambda functions', () => {
const resourceType = 'AWS::Lambda::Function';
const resourceId = 'my-lambda-function';
assert.strictEqual(
getLogGroupName(resourceType, resourceId),
'/aws/lambda/my-lambda-function',
);
});

void it('returns correct log group name for API Gateway', () => {
const resourceType = 'AWS::ApiGateway::RestApi';
const resourceId = 'abc123def';
assert.strictEqual(
getLogGroupName(resourceType, resourceId),
// eslint-disable-next-line spellcheck/spell-checker
'API-Gateway-Execution-Logs_abc123def',
);
});

void it('returns correct log group name for AppSync APIs', () => {
const resourceType = 'AWS::AppSync::GraphQLApi';
// eslint-disable-next-line spellcheck/spell-checker
const resourceId = 'xyz789';
assert.strictEqual(
getLogGroupName(resourceType, resourceId),
// eslint-disable-next-line spellcheck/spell-checker
'/aws/appsync/apis/xyz789',
);
});

void it('returns null for unsupported resource types', () => {
const resourceType = 'AWS::S3::Bucket';
const resourceId = 'my-bucket';

const result = getLogGroupName(resourceType, resourceId);

assert.strictEqual(result, null);
});

void it('handles resource IDs with special characters', () => {
const resourceType = 'AWS::Lambda::Function';
const resourceId = 'my-function-with-special/chars';
assert.strictEqual(
getLogGroupName(resourceType, resourceId),
'/aws/lambda/my-function-with-special/chars',
);
});

void it('handles resource IDs with ARN format', () => {
const resourceType = 'AWS::Lambda::Function';
const resourceId =
'arn:aws:lambda:us-west-2:123456789012:function:my-function';
assert.strictEqual(
getLogGroupName(resourceType, resourceId),
'/aws/lambda/arn:aws:lambda:us-west-2:123456789012:function:my-function',
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Determines the CloudWatch Logs log group name for a given resource type and ID
* @param resourceType The AWS resource type
* @param resourceId The resource ID
* @returns The log group name or null if the resource type is not supported
*/
export const getLogGroupName = (
resourceType: string,
resourceId: string,
): string | null => {
switch (resourceType) {
case 'AWS::Lambda::Function':
return `/aws/lambda/${resourceId}`;
case 'AWS::ApiGateway::RestApi':
return `API-Gateway-Execution-Logs_${resourceId}`;
case 'AWS::AppSync::GraphQLApi':
// eslint-disable-next-line spellcheck/spell-checker
return `/aws/appsync/apis/${resourceId}`;
default:
return null;
}
};
Loading
Loading