-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed need for hosting integration files in more than one bucket
* Introduced parameter groups in the CF tempÃlate * Grouped parameters and made metric statistics ingester and metric ingester optional * Fixed error in making metric ingesters optional * Made it possible to decide whether to omit creating a cloudtrail and a s3 bucket in the main cf file - the other should now be redundant * Deleted cloudformation-no-trail * Made the bucket for the lambda files a parameter and deleted the cloudformation_test file * Made it possible for users to choose their own s3 bucket to retrieve lambda files from * Added resources to copy zip file content from one bucket * Updated inline code for lambda zil copier and used new bucket location for ingester * Updated s3bucket location for lambdas to find code * Added depends on for the lambdas using zip copier and added log group retention setting for it * Added condition for creating the copy zip resources * Removed option to set custom s3 bucket location - will hopefully add later * Removed override lambda files location parameter * Simplified deploy script * Bumped the version (manually) and updated deploy scripts * Added S3 bucket location as a parameter. * Used logger for print in lambda zip code * Added some information regarding how the integration works in the readme. * Updated changelog. * Structued the changelog update * Added the S3 key for the lambda code files as a parameter, updated the parameter descriptions, and removed the option for versions * Updated the changelog * Removed versioning deployment scripts and Makefile * Added comment for CopyZipLambda * Changed name from prefix to key * Updated bucket name to logscale * Added comment with where copy zip is from * Updated name related to zip and bucket to be logscale * Updated the README to use LogScale * Replaced Humio with LogScale in CF file * Updated relevant names from Humio to LogScale in helper.py * Updated names in logs_backfiller to logscale * Updated relevant names to LogScale in logs_ingester.py * Updated relevant names to LogScale in logs_subscriber.py * Updated relevant names to LogScale in metric .py files * Updated CopyZipLambda file with function descriptions * Updated name * Added name update in ChangeLog * Fixed error in CopyZipLambda and updated deploy scripts with logscale bucket * Re-added versioning to package name, so that update is possible * Cleaned up permissions * Updated changelog * Updated the readme with section regarding adding a new region * Fixed minor mistake in changelog * Updated date for last changelog entry * Fixed errors in changelog * Fixed comment in copyziplambda * Small changes to the readme * Changed to lowercase lambda and removed outcommented deploy commands * Small update in wording * Added most important change in the changelog overview Co-authored-by: Zanna <suzanna.volkov@crowdstrike.com>
- Loading branch information
1 parent
bcbd866
commit 9c3b9d4
Showing
16 changed files
with
496 additions
and
1,412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# This file contains the inline code for the lambda named "LogScaleCloudWatchCopyZipLambda". | ||
# This code is copied directly into the CF resource, and thus this file is only to have an overview. | ||
# This code is based on the inline code from the following GitHub library https://github.com/aws-quickstart/quickstart-examples/blob/main/patterns/LambdaZips/example.yaml. | ||
|
||
import json | ||
import logging | ||
import os | ||
import threading | ||
import boto3 | ||
import cfnresponse | ||
|
||
level = os.getenv("log_level", "INFO") | ||
logging.basicConfig(level=level) | ||
logger = logging.getLogger() | ||
logger.setLevel(level) | ||
|
||
|
||
def copy_objects(source_bucket, dest_bucket, key): | ||
""" | ||
Copy key from source bucket to destination bucket. | ||
:param source_bucket: S3 bucket containing zip file with code. | ||
:param dest_bucket: S3 bucket where zip file with code should be copied to. | ||
:param key: File name to be copied. | ||
:return: None | ||
""" | ||
s3 = boto3.client('s3') | ||
copy_source = { | ||
'Bucket': source_bucket, | ||
'Key': key | ||
} | ||
logger.debug(('copy_source: %s' % copy_source)) | ||
logger.debug(('dest_bucket = %s' % dest_bucket)) | ||
logger.debug(('key = %s' % key)) | ||
s3.copy_object(CopySource=copy_source, Bucket=dest_bucket, Key=key) | ||
|
||
|
||
def delete_objects(bucket, key): | ||
""" | ||
Delete a bucket and its objects. | ||
:param bucket: S3 bucket to be deleted. | ||
:param key: S3 key to object that should be deleted. | ||
:return: | ||
""" | ||
s3 = boto3.client('s3') | ||
objects = {'Objects': [{'Key': key}]} | ||
s3.delete_objects(Bucket=bucket, Delete=objects) | ||
|
||
|
||
def timeout(event, context): | ||
""" | ||
Send a response to the custom resource if it times out. | ||
:param event: Event data from the lambda. | ||
:param context: Lambda context object. | ||
:return: None | ||
""" | ||
logging.error('Execution is about to time out, sending failure response to CloudFormation') | ||
cfnresponse.send(event, context, cfnresponse.FAILED, {}, None) | ||
|
||
|
||
def handler(event, context): | ||
""" | ||
Lambda handler that will copy the zip file from the source bucket to the | ||
destination bucket. | ||
It will send a failure to CloudFormation if the function is going to timeout. | ||
:param event: Event data from caller. | ||
:param context: Lambda context object. | ||
:return: None | ||
""" | ||
timer = threading.Timer((context.get_remaining_time_in_millis() | ||
/ 1000.00) - 0.5, timeout, args=[event, context]) | ||
timer.start() | ||
logger.debug(('Received event: %s' % json.dumps(event))) | ||
status = cfnresponse.SUCCESS | ||
try: | ||
source_bucket = event['ResourceProperties']['SourceBucket'] | ||
dest_bucket = event['ResourceProperties']['DestBucket'] | ||
key = event['ResourceProperties']['Key'] | ||
if event['RequestType'] == 'Delete': | ||
delete_objects(dest_bucket, key) | ||
else: | ||
copy_objects(source_bucket, dest_bucket, key) | ||
except Exception as e: | ||
logging.error('Exception: %s' % e, exc_info=True) | ||
status = cfnresponse.FAILED | ||
finally: | ||
timer.cancel() | ||
cfnresponse.send(event, context, status, {}, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.