In python, the same shasum from aws lambda
ldata = ''
with open(localfilepath,'rb') as f:
ldata = f.read()
# openssl equivalent command used
# $openssl dgst -sha256 -binary <binary_file> | openssl enc -base64
if ldata:
m = hashlib.sha256()
m.update(ldata)
s3_digest = m.digest()
local_codesha256 = b64encode(s3_digest)
To verify, with the aws env set correctly,(assuming, aws token and creds are set correctly for this cli to work) compare the CodeSha256. ( using python boto3 client to get lambda details.)
$ aws lambda get-function --function-name <functionname>
{
"Configuration": {
"FunctionName": "-----------",
"FunctionArn": "arn:aws:lambda:us--1:----:function:-----",
"Runtime": "nodejs10.x",
"Role": "arn:aws:iam::-------:role/-------------",
"Handler": "--------- ",
"CodeSize": 10042831,
"Description": "",
"Timeout": 300,
"MemorySize": 3008,
"LastModified": "2019-10-09T23:44:08.222+0000",
"CodeSha256": "aAMvEdR/MSq0x89LzD0L37+AZceFzhtrb9eymqczAh8=",
"Version": "$LATEST",
"Environment": {
"Variables": {
...
}
}
..}
.}
aws lambda list
response = None
resp_functions = []
lc = boto3.client('lambda',
aws_access_key_id=<-----> ,
aws_secret_access_key=<--->,
aws_session_token=<--->,
region_name=<--->)
try:
response = lc.list_functions()
while True:
resp_functions.extend(response['Functions'][:])
# copy the function and iterate with next marker
if 'NextMarker' in response:
response = lc.list_functions(Marker=response['NextMarker'])
else:
break
except Exception as ex:
raise ex