How to use the cfnresponse.SUCCESS function in cfnresponse

To help you get started, we’ve selected a few cfnresponse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github moduspwnens / boa-chat / boa-nimbus / lambda / S3ObjectWriterFunction / index.py View on Github external
"Metadata": s3_object_metadata
        }
        
        if "Content-Type" in resource_properties:
            put_object_kwargs["ContentType"] = resource_properties["Content-Type"]
        
        s3_client.put_object(**put_object_kwargs)
        
    elif request_type == "Delete":
        
        s3_client.delete_object(
            Bucket = s3_bucket_name,
            Key = s3_object_key
        )
        
    cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, None)

    return {}
github moduspwnens / boa-chat / boa-nimbus / lambda / StepFunctionStateMachineCustomResourceFunction / index.py View on Github external
)
        except botocore.exceptions.ClientError as e:
            if e.response['Error']['Code'] == 'InvalidDefinition':
                cfnresponse.send(event, context, cfnresponse.FAILED, {}, physical_resource_id)
            raise
        
        state_machine_arn = response["stateMachineArn"]
        
        physical_resource_id = state_machine_arn
        
        response_dict["StateMachineArn"] = state_machine_arn
        response_dict["StateMachineName"] = state_machine_name
        
        

    cfnresponse.send(event, context, cfnresponse.SUCCESS, response_dict, physical_resource_id)

    return {}
github awslabs / aws-service-catalog-products / service-control-policy / scp-create / v1 / src / create_policy / lambda_function.py View on Github external
try:
        policy_id = event['PhysicalResourceId']
        session = assume_role(org_role, "UpdatePolicy")
        client = session.client('organizations')

        response = client.update_policy(
            Content=get_policy(event),
            Description=policy_description,
            Name=policy_name,
            PolicyId=policy_id
        )

        policy_id = response['Policy']['PolicySummary']['Id']
        logging.info("Policy Updated. Policy Id {0}".format(policy_id))
        status = cfnresponse.SUCCESS

    except BaseException as ex:
        logging.exception(ex)

    finally:
        cfnresponse.send(event=event, context=context, responseStatus=status, responseData=data,
                         physicalResourceId=policy_id)
github aws-samples / amazon-personalize-data-conversion-pipeline / functions / generate_schema / app.py View on Github external
try:
        if event['RequestType'] == 'Create':
            object = s3.Object(schema_bucket, schema_filename)
            object.put(Body=str.encode(json.dumps(schema_template, indent=4)))
            response_data = {"Message": "Resource creation successful!", "Schema": 's3://{}/{}'.format(schema_bucket, schema_filename)}
            cfnresponse.send(event, context, cfnresponse.SUCCESS, response_data)
        elif event['RequestType'] == 'Update':
            object = s3.Object(schema_bucket, schema_filename)
            object.put(Body=str.encode(json.dumps(schema_template, indent=4)))
            response_data = {"Message": "Resource creation successful!", "Schema": 's3://{}/{}'.format(schema_bucket, schema_filename)}
            cfnresponse.send(event, context, cfnresponse.SUCCESS, response_data)
        elif event['RequestType'] == 'Delete':
            s3.Object(schema_bucket, schema_filename).delete()
            s3.Object(schema_bucket, schema_filename+'.temp').delete()
            response_data = {"Message": "Resource deletion successful!"}
            cfnresponse.send(event, context, cfnresponse.SUCCESS, response_data)
        else:
            response_data = {"Message": "Unexpected event received from CloudFormation"}
            cfnresponse.send(event, context, cfnresponse.SUCCESS, response_data)

    except Exception as error:         
        print(error)
        response_data = {"Message": "Unexpected error occured."}
        cfnresponse.send(event, context, cfnresponse.FAILED, response_data)
github awslabs / aws-servicebroker / build-tools / apb_packaging / sb_cfn_package / functions / generate_password / lambda_function.py View on Github external
def handler(event, context):
    response_code = cfnresponse.SUCCESS
    response_data = {}
    print(event)
    if event['RequestType'] == 'Create':
        phys_id = ''.join(random.choice(alnum) for _ in range(16))
    else:
        phys_id = event['PhysicalResourceId']
    try:
        if event['RequestType'] in ['Create', 'Update']:
            if 'Length' in event['ResourceProperties']:
                pw_len = int(event['ResourceProperties']['Length'])
            else:
                pw_len = 16
            response_data['MasterUserPassword'] = generate_password(pw_len)
        cfnresponse.send(event, context, response_code, response_data, phys_id)
    except Exception as e:
        print(str(e))
github ab77 / cfn-generic-custom-resource / generic_provider / generic_provider.py View on Github external
)
                return False


        ''' Create: (re)creates a resource and returns PhysicalResourceId based on
            the specified AgentResourceId.'''
        try:
            (PhysicalResourceId, responseData) = self.handle_client_event(
                agent,
                event,
                create=True
            )
            cfnresponse.send(
                event,
                context,
                cfnresponse.SUCCESS,
                responseData=responseData,
                physicalResourceId=PhysicalResourceId,
                noEcho=no_echo
            )
            return True
        except Exception as e:
            if self.verbose: print_exc()
            cfnresponse.send(
                event,
                context,
                cfnresponse.FAILED,
                noEcho=no_echo,
                physicalResourceId=CreateFailedResourceId,
                reason=str(e)
            )
            return False
github ab77 / cfn-generic-custom-resource / generic_provider / generic_provider.py View on Github external
LogicalResourceId = event['LogicalResourceId']
            CreateFailedResourceId = '{}-CREATE_FAILED'.format(LogicalResourceId)
            if agent_type == 'client':
                agent = self.session.client(agent_service, **kwargs)
            if agent_type == 'resource':
                try:
                    agent = self.session.resource(agent_service, **kwargs)
                    (physicalResourceId, responseData) = self.handle_resource_event(
                        agent,
                        event
                    )
                    assert physicalResourceId and responseData
                    cfnresponse.send(
                        event,
                        context,
                        cfnresponse.SUCCESS,
                        responseData=responseData,
                        physicalResourceId=physicalResourceId,
                        noEcho=no_echo
                    )
                    return True
                except Exception as e:
                    if self.verbose: print_exc()
                    cfnresponse.send(
                        event,
                        context,
                        cfnresponse.FAILED,
                        noEcho=no_echo,
                        reason=str(e)
                    )
                return False
            if agent_type == 'custom':
github PaloAltoNetworks / TransitGatewayDeployment / source / lambda package / TransitGatewayInitialiseLambda.py View on Github external
cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData, "CustomResourcePhysicalID")
        logger.info("Sending cfn success message ")

    elif event['RequestType'] == 'Update':
        print("Update something")

    elif event['RequestType'] == 'Delete':
        print("Got Delete event")
        try:
            res = delete_route(toTGWRouteTable, vnetroutecidr)
            res1 = delete_route(VPC0_route_table_id, defroutecidr)


        except Exception as e:
            print("Errory trying to delete something")
            cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData, "CustomResourcePhysicalID")
github nordcloud / cfn-encrypt / cfn_encrypt / ssm_parameter.py View on Github external
if event["RequestType"] in ["Create", "Update"]:
            if event["RequestType"] == "Create" and parameter_exist(name):
                raise NameError("A Parameter named {} already exists".format(name))

            response = boto3.client('ssm').put_parameter(
                Name=name,
                Description=event["ResourceProperties"]["Description"],
                Value=event["ResourceProperties"]["Value"],
                Type="SecureString",
                KeyId=event["ResourceProperties"]["KeyId"],
                Overwrite=True
            )

            logger.info("Successfully stored parameter {}".format(name))

            cfnresponse.send(event, context, cfnresponse.SUCCESS, response, name)
        else:
            boto3.client('ssm').delete_parameter(
                Name=event["PhysicalResourceId"],
            )
            logger.info("Successfully deleted parameter: {}".format(name))
            cfnresponse.send(event, context, cfnresponse.SUCCESS, None, name)

    except Exception as ex:
        logger.error("Faild to %s parameter: %s", event["RequestType"], name)
        logger.debug("Stack trace %s", traceback.format_exc())
        if event["RequestType"] in ["Create", "Update"]:
            cfnresponse.send(event, context, cfnresponse.FAILED, None, "0")
        else:
            cfnresponse.send(event, context, cfnresponse.SUCCESS, None, "0")
github jorgebastida / gordon / gordon / contrib / helpers / sleep / sleep.py View on Github external
def handler(event, context):
    if event['RequestType'] == 'Delete':
        send(event, context, SUCCESS)
        return
    time.sleep(int(event['ResourceProperties']['Time']))
    send(event, context, SUCCESS)

cfnresponse

Send a response object to a custom resource by way of an Amazon S3 presigned URL

Apache-2.0
Latest version published 4 months ago

Package Health Score

58 / 100
Full package analysis

Similar packages