Best Python code snippet using localstack_python
test_lambda_function_urls.py
Source:test_lambda_function_urls.py
...5from uuid import uuid46from .utilities import get_test_zip_file1, get_role_name7@mock_lambda8@pytest.mark.parametrize("key", ["FunctionName", "FunctionArn"])9def test_create_function_url_config(key):10 client = boto3.client("lambda", "us-east-2")11 function_name = str(uuid4())[0:6]12 fxn = client.create_function(13 FunctionName=function_name,14 Runtime="python3.7",15 Role=get_role_name(),16 Handler="lambda_function.lambda_handler",17 Code={"ZipFile": get_test_zip_file1()},18 )19 name_or_arn = fxn[key]20 resp = client.create_function_url_config(21 AuthType="AWS_IAM", FunctionName=name_or_arn22 )23 resp.should.have.key("FunctionArn").equals(fxn["FunctionArn"])24 resp.should.have.key("AuthType").equals("AWS_IAM")25 resp.should.have.key("FunctionUrl")26 resp = client.get_function_url_config(FunctionName=name_or_arn)27 resp.should.have.key("FunctionArn").equals(fxn["FunctionArn"])28 resp.should.have.key("AuthType").equals("AWS_IAM")29 resp.should.have.key("FunctionUrl")30@mock_lambda31def test_create_function_url_config_with_cors():32 client = boto3.client("lambda", "us-east-2")33 function_name = str(uuid4())[0:6]34 fxn = client.create_function(35 FunctionName=function_name,36 Runtime="python3.7",37 Role=get_role_name(),38 Handler="lambda_function.lambda_handler",39 Code={"ZipFile": get_test_zip_file1()},40 )41 name_or_arn = fxn["FunctionName"]42 resp = client.create_function_url_config(43 AuthType="AWS_IAM",44 FunctionName=name_or_arn,45 Cors={46 "AllowCredentials": True,47 "AllowHeaders": ["date", "keep-alive"],48 "AllowMethods": ["*"],49 "AllowOrigins": ["*"],50 "ExposeHeaders": ["date", "keep-alive"],51 "MaxAge": 86400,52 },53 )54 resp.should.have.key("Cors").equals(55 {56 "AllowCredentials": True,57 "AllowHeaders": ["date", "keep-alive"],58 "AllowMethods": ["*"],59 "AllowOrigins": ["*"],60 "ExposeHeaders": ["date", "keep-alive"],61 "MaxAge": 86400,62 }63 )64@mock_lambda65def test_update_function_url_config_with_cors():66 client = boto3.client("lambda", "us-east-2")67 function_name = str(uuid4())[0:6]68 fxn = client.create_function(69 FunctionName=function_name,70 Runtime="python3.7",71 Role=get_role_name(),72 Handler="lambda_function.lambda_handler",73 Code={"ZipFile": get_test_zip_file1()},74 )75 name_or_arn = fxn["FunctionName"]76 resp = client.create_function_url_config(77 AuthType="AWS_IAM",78 FunctionName=name_or_arn,79 Cors={80 "AllowCredentials": True,81 "AllowHeaders": ["date", "keep-alive"],82 "AllowMethods": ["*"],83 "AllowOrigins": ["*"],84 "ExposeHeaders": ["date", "keep-alive"],85 "MaxAge": 86400,86 },87 )88 resp = client.update_function_url_config(89 FunctionName=name_or_arn, AuthType="NONE", Cors={"AllowCredentials": False}90 )91 resp.should.have.key("Cors").equals({"AllowCredentials": False})92@mock_lambda93@pytest.mark.parametrize("key", ["FunctionName", "FunctionArn"])94def test_delete_function_url_config(key):95 client = boto3.client("lambda", "us-east-2")96 function_name = str(uuid4())[0:6]97 fxn = client.create_function(98 FunctionName=function_name,99 Runtime="python3.7",100 Role=get_role_name(),101 Handler="lambda_function.lambda_handler",102 Code={"ZipFile": get_test_zip_file1()},103 )104 name_or_arn = fxn[key]105 client.create_function_url_config(AuthType="AWS_IAM", FunctionName=name_or_arn)106 client.delete_function_url_config(FunctionName=name_or_arn)107 # It no longer exists108 with pytest.raises(ClientError):...
_manager.py
Source:_manager.py
...34 response = self._client.get_function_url_config(FunctionName=name)35 url = response["FunctionUrl"]36 return LambdaFunctionMetadata(name, url, role)37 def _create_lambda_function_public_url(self, name):38 response = self._client.create_function_url_config(39 FunctionName=name,40 AuthType="NONE",41 )42 function_url = response['FunctionUrl']43 self._client.add_permission(44 Action="lambda:InvokeFunctionUrl",45 FunctionName=name,46 Principal="*",47 StatementId="FunctionURLAllowPublicAccess",48 FunctionUrlAuthType="NONE",49 )50 return function_url51 def _create_lambda_function(self, name, role, handler_name, zip_file):52 self._client.create_function(...
lambda_function_url.py
Source:lambda_function_url.py
...68 )69#%%70### Create Lambda Function URL71client_lambda = boto3.client('lambda')72response_create_function_url_config = client_lambda.create_function_url_config(73 FunctionName='test_Lambda_Function_URLs_boto3',74 AuthType='NONE'75 )76function_URL = response_create_function_url_config['FunctionUrl']77print(function_URL)78import requests79response_requests = requests.get(function_URL)...
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!!