Skip to content

Commit

Permalink
Merge branch 'develop' v0.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
rstrahan committed Oct 11, 2023
2 parents 2c1c5a6 + 149dc38 commit 13bf4d8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- #187 - Got error message in PostCallAnalyticsWorkflow step function
- #189 - Uploading some MP3 files fails to trigger workflow - files remain unprocessed
- #190 - Transcription search web UI opens with an error page after deployment
- #199 - BedrockBoto3 stack update failure when lambda function is replaced during update

## [0.7.2] - 2023-10-03
### Fixed
Expand Down
28 changes: 19 additions & 9 deletions pca-boto3-bedrock/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Resources:
import boto3
import zipfile
import urllib3
import json
from datetime import datetime
import cfnresponse
boto3_bucket = os.environ['BOTO3_BUCKET']
Expand All @@ -90,16 +91,21 @@ Resources:
os.path.join(path, '..')))
zipf.close()
def empty_bucket(bucket_name):
def deleteObject(existingZip):
print(f'Deleting Existing Zip: {existingZip}')
s3_client = boto3.client('s3')
response = s3_client.list_objects_v2(Bucket=bucket_name)
if 'Contents' in response:
keys = [{'Key': obj['Key']} for obj in response['Contents']]
s3_client.delete_objects(Bucket=bucket_name, Delete={'Objects': keys})
s3_client.delete_object(Bucket=existingZip["Bucket"], Key=existingZip["Key"])
return
def handler(event, context):
print("Event: ", event)
print("Event: ", json.dumps(event))
physicalResourceId = event.get("PhysicalResourceId", None)
existingZip = None
if physicalResourceId:
try:
existingZip = json.loads(physicalResourceId)
except:
existingZip = ""
responseData={}
reason=""
status = cfnresponse.SUCCESS
Expand All @@ -113,14 +119,17 @@ Resources:
print(f"uploading {boto3_zip_name} to s3 bucket {boto3_bucket}")
upload_file_to_s3(boto3_zip_name, boto3_bucket, boto3_zip_name)
responseData = {"Bucket": boto3_bucket, "Key": boto3_zip_name}
physicalResourceId = json.dumps(responseData)
else:
# delete - empty the bucket so it can be deleted by the stack.
empty_bucket(boto3_bucket)
print(f"RequestType is: {event['RequestType']}")
except Exception as e:
print(e)
status = cfnresponse.FAILED
reason = f"Exception thrown: {e}"
cfnresponse.send(event, context, status, responseData, reason=reason)
# delete any previously created zip file (during update or delete), so that bucket can be deleted
if existingZip:
deleteObject(existingZip)
cfnresponse.send(event, context, status, responseData, reason=reason, physicalResourceId=physicalResourceId)
Metadata:
cfn_nag:
rules_to_suppress:
Expand All @@ -135,6 +144,7 @@ Resources:
ServiceToken: !GetAtt BedrockBoto3ZipFunction.Arn
# Rerun BedrockBoto3ZipFunction if any of the following parameters change
BOTO3_BUCKET: !Ref BedrockBoto3Bucket
VERSION: 1

BedrockBoto3Layer:
Type: "AWS::Lambda::LayerVersion"
Expand Down

0 comments on commit 13bf4d8

Please sign in to comment.