Skip to content

Commit

Permalink
Merge branch 'master' into AL-pe-SQS
Browse files Browse the repository at this point in the history
  • Loading branch information
aloftus23 committed Oct 5, 2023
2 parents 1e5853e + e28e872 commit 5f55870
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions backend/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ provider:
- s3:GetObjectAcl
- s3:PutObject
- s3:PutObjectAcl
- s3:PutBucketAcl
- s3:GetBucketAcl
Resource: '*'
- Effect: Allow
Action:
Expand All @@ -78,6 +80,14 @@ provider:
- logs:StartLiveTail
- logs:StopLiveTail
Resource: '*'
- Effect: Allow
Action:
- ssm:DescribeParameters
- ssm:GetParameter
- ssm:GetParameters
- ssm:GetParametersByPath
- ssm:PutParameter
Resource: '*'

resources:
Resources:
Expand Down
11 changes: 10 additions & 1 deletion backend/src/tasks/cloudwatchToS3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ export const handler = async () => {

while (true) {
const response = await logs.send(new DescribeLogGroupsCommand(extra_args));
console.log(`response: ${JSON.stringify(response)}`);
log_groups = log_groups.concat(response.logGroups!);

console.log(`log_groups: ${JSON.stringify(log_groups)}`);
if (!response.nextToken) {
break;
}
Expand All @@ -46,16 +47,23 @@ export const handler = async () => {
const command = new ListTagsForResourceCommand({
resourceArn: `arn:aws:logs:${region}:${accountId}:log-group:${log_group.logGroupName}`
});
console.log(`Processing log group: ${log_group.logGroupName}`);
console.log(`command: ${JSON.stringify(command)}`);
const response = await logs.send(command);
console.log(`log group response: ${JSON.stringify(response)}`);
const log_group_tags = response.tags || {};

if (log_group_tags.ExportToS3 === 'true') {
log_groups_to_export.push(log_group.logGroupName!);
}
console.log(
`log_groups_to_export: ${JSON.stringify(log_groups_to_export)}`
);
await delay(10 * 1000); // prevents LimitExceededException (AWS allows only one export task at a time)
}

for (const log_group_name of log_groups_to_export) {
console.log('Processing log group: ' + log_group_name);
const ssm_parameter_name = (
'/log-exporter-last-export/' + log_group_name
).replace('//', '/');
Expand All @@ -70,6 +78,7 @@ export const handler = async () => {
if (error.name !== 'ParameterNotFound') {
console.error('Error fetching SSM parameter: ' + error.message);
}
console.error(`error: ${error.message}`);
}

const export_to_time = Math.round(Date.now());
Expand Down

0 comments on commit 5f55870

Please sign in to comment.