initial version of counter lambda function
This commit is contained in:
55
example-projects/counter-demo/aws-lambda/start.py
Normal file
55
example-projects/counter-demo/aws-lambda/start.py
Normal file
@ -0,0 +1,55 @@
|
||||
import boto3
|
||||
import zipfile
|
||||
|
||||
################################################################################################
|
||||
#
|
||||
# Configuration Parameters
|
||||
#
|
||||
################################################################################################
|
||||
|
||||
region = 'eu-central-1'
|
||||
functionName = 'cloudcomp-counter-lambda-demo'
|
||||
roleName = 'arn:aws:iam::309000625112:role/service-role/cloudcomp-counter-demo-role-6rs7pah3'
|
||||
|
||||
|
||||
################################################################################################
|
||||
#
|
||||
# boto3 code
|
||||
#
|
||||
################################################################################################
|
||||
|
||||
|
||||
client = boto3.setup_default_session(region_name=region)
|
||||
lClient = boto3.client('lambda')
|
||||
|
||||
|
||||
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()
|
||||
|
||||
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,
|
||||
)
|
Reference in New Issue
Block a user