Best Python code snippet using localstack_python
lambda_api.py
Source:lambda_api.py
...1000 lambda_details.vpc_config = data['VpcConfig']1001 if data.get('KMSKeyArn'):1002 lambda_details.kms_key_arn = data['KMSKeyArn']1003 return jsonify(data)1004def generate_policy_statement(sid, action, arn, sourcearn, principal):1005 statement = {1006 'Sid': sid,1007 'Effect': 'Allow',1008 'Action': action,1009 'Resource': arn,1010 }1011 # Adds SourceArn only if SourceArn is present1012 if sourcearn:1013 condition = {1014 'ArnLike': {1015 'AWS:SourceArn': sourcearn1016 }1017 }1018 statement['Condition'] = condition1019 # Adds Principal only if Principal is present1020 if principal:1021 principal = {1022 'Service': principal1023 }1024 statement['Principal'] = principal1025 return statement1026def generate_policy(sid, action, arn, sourcearn, principal):1027 new_statement = generate_policy_statement(sid, action, arn, sourcearn, principal)1028 policy = {1029 'Version': IAM_POLICY_VERSION,1030 'Id': 'LambdaFuncAccess-%s' % sid,1031 'Statement': [new_statement]1032 }1033 return policy1034@app.route('%s/functions/<function>/policy' % PATH_ROOT, methods=['POST'])1035def add_permission(function):1036 data = json.loads(to_str(request.data))1037 iam_client = aws_stack.connect_to_service('iam')1038 sid = data.get('StatementId')1039 action = data.get('Action')1040 principal = data.get('Principal')1041 sourcearn = data.get('SourceArn')...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!