in packages/app/src/handlers/set-log-shipping.ts [25:94]
export async function setLogShipping(trigger: unknown): Promise<void> {
const clientConfig = awsClientConfig();
const cloudwatchLogs = new CloudWatchLogs(clientConfig);
const s3 = new S3(clientConfig);
const lambda = new Lambda(clientConfig);
const ecs = new ECS(clientConfig);
console.log('Configuring log shipping');
console.log(JSON.stringify(trigger));
const {
logNamePrefixes,
logShippingFilterName,
logShippingLambdaArn,
structuredDataBucket,
structuredDataKey,
} = getConfigureLogShippingConfig();
await updateStructuredFieldsData(
s3,
lambda,
ecs,
structuredDataBucket,
structuredDataKey,
);
const logShippingLambdaName = logShippingLambdaArn.split(':')[6];
// get list of log groups
const allGroups = await getCloudWatchLogGroups(cloudwatchLogs);
// subscribe those groups that should have shipping enabled
const logShippingLambdaLogGroupName = `/aws/lambda/${logShippingLambdaName}`;
console.log(
`Excluding ${logShippingLambdaLogGroupName} from eligible log groups`,
);
const logShippingGroups = allGroups.filter((group) => {
return eligibleForLogShipping(
logNamePrefixes,
group.logGroupName!,
logShippingLambdaLogGroupName,
);
});
console.log(
`${
logShippingGroups.length
} groups eligible for log shipping: ${logShippingGroups
.map((group) => group.logGroupName!)
.join(', ')}`,
);
await subscribeGroups(
cloudwatchLogs,
logShippingGroups,
logShippingFilterName,
logShippingLambdaArn,
);
const removeShippingGroups = allGroups.filter((group) => {
return !eligibleForLogShipping(
logNamePrefixes,
group.logGroupName!,
logShippingLambdaLogGroupName,
);
});
await unsubscribeGroups(
cloudwatchLogs,
removeShippingGroups,
logShippingFilterName,
);
}