You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the guide you provide. It is very useful. However, I face some issue for the lambda coding.
On the first run of a job, it creates the log stream and everything is fine. However, on subsequent jobs (update event log on next minutes) I get the error that the "The specified log group already exists", even though this job was the one that created it. The error as follows:
[ERROR] ResourceAlreadyExistsException: An error occurred (ResourceAlreadyExistsException) when calling the CreateLogGroup operation: The specified log group already exists
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 86, in lambda_handler
createLogGroup(logGroupName)
File "/var/task/lambda_function.py", line 12, in createLogGroup
createLogGroupResponse = cwlogs.create_log_group(
File "/var/runtime/botocore/client.py", line 386, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/runtime/botocore/client.py", line 705, in _make_api_call
raise error_class(parsed_response, operation_name)
The lambda code I used is as ur doc:
import os
import boto3
import string
import random
import json
import time
def ifLogGroupExists(logGroupName):
listLogGroupsResponse = cwlogs.describe_log_groups()
for logGroup in listLogGroupsResponse["logGroups"]:
if logGroupName in logGroup["logGroupName"]:
return True
return False
Hi Mr. GeorgeDavis,
Thanks for the guide you provide. It is very useful. However, I face some issue for the lambda coding.
On the first run of a job, it creates the log stream and everything is fine. However, on subsequent jobs (update event log on next minutes) I get the error that the "The specified log group already exists", even though this job was the one that created it. The error as follows:
[ERROR] ResourceAlreadyExistsException: An error occurred (ResourceAlreadyExistsException) when calling the CreateLogGroup operation: The specified log group already exists
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 86, in lambda_handler
createLogGroup(logGroupName)
File "/var/task/lambda_function.py", line 12, in createLogGroup
createLogGroupResponse = cwlogs.create_log_group(
File "/var/runtime/botocore/client.py", line 386, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/runtime/botocore/client.py", line 705, in _make_api_call
raise error_class(parsed_response, operation_name)
The lambda code I used is as ur doc:
import os
import boto3
import string
import random
import json
import time
cwlogs = boto3.client('logs')
def createLogGroup(logGroupName):
createLogGroupResponse = cwlogs.create_log_group(
logGroupName=logGroupName,
tags={
"Owner": "TrendMicro",
"Product": "CloudOneWorkloadSecurity",
"Name": logGroupName
}
)
def ifLogGroupExists(logGroupName):
listLogGroupsResponse = cwlogs.describe_log_groups()
for logGroup in listLogGroupsResponse["logGroups"]:
if logGroupName in logGroup["logGroupName"]:
return True
return False
def createLogStream(logGroupName, logStreamName):
createLogStreamResponse = cwlogs.create_log_stream(
logGroupName=logGroupName,
logStreamName=logStreamName
)
def putLogEvents(logGroupName, logStreamName, logEvent, nextSequenceToken=None):
def lambda_handler(event, context):
Regards,
Alex Lai (alex.lai@ecloudvalley.com)
The text was updated successfully, but these errors were encountered: