You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.5 KiB

  1. import boto3
  2. import zipfile
  3. ################################################################################################
  4. #
  5. # Configuration Parameters
  6. #
  7. ################################################################################################
  8. region = 'eu-central-1'
  9. functionName = 'cloudcomp-counter-lambda-demo'
  10. roleName = 'arn:aws:iam::309000625112:role/service-role/cloudcomp-counter-demo-role-6rs7pah3'
  11. ################################################################################################
  12. #
  13. # boto3 code
  14. #
  15. ################################################################################################
  16. client = boto3.setup_default_session(region_name=region)
  17. lClient = boto3.client('lambda')
  18. print("Deleting old function...")
  19. print("------------------------------------")
  20. try:
  21. response = lClient.delete_function(
  22. FunctionName=functionName,
  23. )
  24. except lClient.exceptions.ResourceNotFoundException:
  25. print('Function not available. No need to delete it.')
  26. print("creating new function...")
  27. print("------------------------------------")
  28. zf = zipfile.ZipFile('lambda-deployment-archive.zip', 'w', zipfile.ZIP_DEFLATED)
  29. zf.write('lambda_function.py')
  30. zf.close()
  31. with open('lambda-deployment-archive.zip', mode='rb') as file:
  32. zipfileContent = file.read()
  33. response = lClient.create_function(
  34. FunctionName=functionName,
  35. Runtime='python3.8',
  36. Role=roleName,
  37. Code={
  38. 'ZipFile': zipfileContent
  39. },
  40. Handler='lambda_function.lambda_handler',
  41. Publish=True,
  42. )