AWSTemplateFormatVersion: 2010-09-09 Description: This CloudFormation Template removes an Elastic Container Registery Repository. (qs-1nlegmi13) Metadata: cfn-lint: { config: { ignore_checks: [W9006, W9002, W9003] } } Parameters: Repository: Description: The Repository to be removed. Type: String ServiceToken: Description: The Role ARN required to run the Custom Resource. Type: String Resources: UpdateConfig: Type: Custom::ConfigFile Properties: ServiceToken: !GetAtt UpdateConfigFunction.Arn Region: !Ref AWS::Region Repository: !Ref Repository UpdateConfigFunction: Type: AWS::Lambda::Function Properties: Description: Removes an ECR Repository. Handler: index.handler Runtime: python3.7 Role: !Ref ServiceToken Timeout: 240 Code: ZipFile: | import json import boto3 import cfnresponse s3 = boto3.resource('s3') def create(properties, physical_id): message = 'Create Complete' print(message) return cfnresponse.SUCCESS, None def update(properties, physical_id): return create(properties, physical_id) def delete(properties, physical_id): region = properties['Region'] repository = properties['Repository'] removeRepository(repository) print('success') return cfnresponse.SUCCESS, physical_id def removeRepository(ecr_repository): client = boto3.client('ecr') response = client.delete_repository( repositoryName=ecr_repository, force=True ) def handler(event, context): print("Received event: %s" % json.dumps(event)) status = cfnresponse.FAILED new_physical_id = None try: properties = event.get('ResourceProperties') physical_id = event.get('PhysicalResourceId') status, new_physical_id = { 'Create': create, 'Update': update, 'Delete': delete }.get(event['RequestType'], lambda x, y: (cfnresponse.FAILED, None))(properties, physical_id) except Exception as e: print("Exception: %s" % e) status = cfnresponse.FAILED finally: cfnresponse.send(event, context, status, {}, new_physical_id)