Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #80 from emoffett/main
Browse files Browse the repository at this point in the history
Update lambda function to supported python version and enable capabilities parameter during stack updates
  • Loading branch information
troy-ameigh authored Sep 12, 2023
2 parents f5cc2e2 + ff71e8f commit 9e0257a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import string
import logging
import threading
import requests
import urllib3 # Added by EM
import json
from botocore.credentials import (
AssumeRoleCredentialFetcher,
Expand All @@ -14,6 +14,8 @@
from botocore.exceptions import ClientError


http = urllib3.PoolManager() # Added by EM

cfn_states = {
"failed": ["CREATE_FAILED", "ROLLBACK_IN_PROGRESS", "ROLLBACK_FAILED", "ROLLBACK_COMPLETE", "DELETE_FAILED",
"UPDATE_ROLLBACK_IN_PROGRESS", "UPDATE_ROLLBACK_FAILED", "UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS",
Expand Down Expand Up @@ -83,9 +85,8 @@ def send(event, context, response_status, response_data, physical_resource_id, l
}

try:
response = requests.put(response_url,
data=json_response_body,
headers=headers)
response = http.request('PUT', response_url, headers=headers, body=json_response_body)

logger.info("CloudFormation returned status code: " + response.reason)
except Exception as e:
logger.error("send(..) failed executing requests.put(..): " + str(e))
Expand Down Expand Up @@ -304,9 +305,6 @@ def create(event, context):
Create a cfn stack using an assumed role
"""

cfn_capabilities = []
if 'capabilities' in event['ResourceProperties'].keys():
cfn_capabilities = event['ResourceProperties']['Capabilities']
cfn_client = boto3.client("cloudformation")
params = get_cfn_parameters(event)
prefix = event['ResourceProperties']['ParentStackId'].split("/")[1]
Expand Down Expand Up @@ -346,17 +344,21 @@ def update(event, context):
Update a cfn stack using an assumed role
"""
stack_id = event["PhysicalResourceId"]
cfn_capabilities = []
capabilities = []
if 'capabilities' in event['ResourceProperties'].keys():
cfn_capabilities = event['ResourceProperties']['capabilities']
capabilities = event['ResourceProperties']['capabilities']
cfn_client = get_client("cloudformation", event, context)
physical_resource_id = stack_id
prefix = event['ResourceProperties']['ParentStackId'].split("/")[1]
parent_properties = cfn_client.describe_stacks(StackName=prefix)['Stacks'][0]
if 'Capabilities' in parent_properties.keys():
capabilities = parent_properties['Capabilities']
try:
cfn_client.update_stack(
StackName=stack_id,
TemplateURL=event['ResourceProperties']['TemplateURL'],
Parameters=get_cfn_parameters(event),
Capabilities=cfn_capabilities,
Capabilities=capabilities,
Tags=[{
'Key': 'ParentStackId',
'Value': event['ResourceProperties']['ParentStackId']
Expand Down

This file was deleted.

0 comments on commit 9e0257a

Please sign in to comment.