import boto3 import zipfile ################################################################################################ # # Configuration Parameters # ################################################################################################ # you need to create a bucket in S3, here in this demo it is called "cloudcomp-counter", but # bucket names need to be world wide unique ;) The demo looks for a file that is named # "us-east-1" (same as our default region) in the bucket and expects a number in it to increase # region = 'eu-central-1' region = 'us-east-1' functionName = 'cloudcomp-counter-lambda-demo' # roleName = 'arn:aws:iam::309000625112:role/service-role/cloudcomp-counter-demo-role-6rs7pah3' roleName = 'arn:aws:iam::919927306708:role/cloudcomp-s3-access' ################################################################################################ # # boto3 code # ################################################################################################ client = boto3.setup_default_session(region_name=region) lClient = boto3.client('lambda') apiClient = boto3.client("apigatewayv2") print("Deleting old function...") print("------------------------------------") try: response = lClient.delete_function( FunctionName=functionName, ) except lClient.exceptions.ResourceNotFoundException: print('Function not available. No need to delete it.') print("creating new function...") print("------------------------------------") zf = zipfile.ZipFile('lambda-deployment-archive.zip', 'w', zipfile.ZIP_DEFLATED) zf.write('lambda_function.py') zf.close() lambdaFunctionARN = "" with open('lambda-deployment-archive.zip', mode='rb') as file: zipfileContent = file.read() response = lClient.create_function( FunctionName=functionName, Runtime='python3.8', Role=roleName, Code={ 'ZipFile': zipfileContent }, Handler='lambda_function.lambda_handler', Publish=True, ) lambdaFunctionARN = response['FunctionArn'] print("creating API gateway...") print("------------------------------------") #apiArn = "" response = apiClient.create_api( Name=functionName + '-api', ProtocolType='HTTP', Target=lambdaFunctionARN ) #apiArn=response[''] #response = lClient.create_event_source_mapping( # EventSourceArn=apiArn, #)