@@ -0,0 +1,1962 @@
+# Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.%0A#%0A# This file is licensed under the Apache License, Version 2.0 (the %22License%22).%0A# You may not use this file except in compliance with the License. A copy of%0A# the License is located at%0A#%0A# http://aws.amazon.com/apache2.0/%0A#%0A# This file is distributed on an %22AS IS%22 BASIS, WITHOUT WARRANTIES OR%0A# CONDITIONS OF ANY KIND, either express or implied. See the License for the%0A# specific language governing permissions and limitations under the License.%0A%0A# snippet-sourcedescription:%5BMyCodeCommitFunction.py demonstrates how to use an AWS Lambda function to return the URLs used for cloning an AWS CodeCommit repository to a CloudWatch log.%5D%0A# snippet-service:%5Bcodecommit%5D%0A# snippet-keyword:%5BPython%5D%0A# snippet-keyword:%5BAWS CodeCommit%5D%0A# snippet-keyword:%5BCode Sample%5D%0A# snippet-keyword:%5BGetRepository%5D%0A# snippet-sourcetype:%5Bfull-example%5D%0A# snippet-sourcedate:%5B2016-03-07%5D%0A# snippet-sourceauthor:%5BAWS%5D%0A# snippet-start:%5Bcodecommit.python.MyCodeCommitFunction.py%5D%0A%0Aimport json%0Aimport boto3%0A%0Acodecommit = boto3.client('codecommit')%0A%0Adef lambda_handler(event, context):%0A    #Log the updated references from the event%0A    references = %7B reference%5B'ref'%5D for reference in event%5B'Records'%5D%5B0%5D%5B'codecommit'%5D%5B'references'%5D %7D%0A    print(%22References: %22  + str(references))%0A    %0A    #Get the repository from the event and show its git clone URL%0A    repository = event%5B'Records'%5D%5B0%5D%5B'eventSourceARN'%5D.split(':')%5B5%5D%0A    try:%0A        response = codecommit.get_repository(repositoryName=repository)%0A        print(%22Clone URL: %22 +response%5B'repositoryMetadata'%5D%5B'cloneUrlHttp'%5D)%0A        return response%5B'repositoryMetadata'%5D%5B'cloneUrlHttp'%5D%0A    except Exception as e:%0A        print(e)%0A        print('Error getting repository %7B%7D. Make sure it exists and that your repository is in the same region as this function.'.format(repository))%0A        raise e%0A%0A# snippet-end:%5Bcodecommit.python.MyCodeCommitFunction.py%5D%0A

Create MyCodeCommitFunction.py