How to use correct_error_response_for_url_config method in localstack

Best Python code snippet using localstack_python

lambda_api.py

Source:lambda_api.py Github

copy

Full Screen

...1230 qualifier = request.args.get("Qualifier")1231 q_arn = func_qualifier(function, qualifier)1232 result = add_permission_policy_statement(function, arn, q_arn, qualifier=qualifier)1233 return result, 2011234def correct_error_response_for_url_config(response):1235 response_data = json.loads(response.data)1236 response_data.update({"Message": response_data.get("message")})1237 response.set_data(json.dumps(response_data))1238 return response1239@app.route("%s/functions/<function>/url" % API_PATH_ROOT_2, methods=["POST"])1240def create_url_config(function):1241 arn = func_arn(function)1242 qualifier = request.args.get("Qualifier")1243 q_arn = func_qualifier(function, qualifier)1244 lambda_backend = LambdaRegion.get()1245 function = lambda_backend.lambdas.get(arn)1246 if function is None:1247 response = error_response("Function does not exist", 404, "ResourceNotFoundException")1248 return correct_error_response_for_url_config(response)1249 if qualifier and not function.qualifier_exists(qualifier=qualifier):1250 return not_found_error()1251 arn = q_arn or arn1252 lambda_backend = LambdaRegion.get()1253 if arn in lambda_backend.url_configs:1254 return error_response(1255 f"Failed to create function url config for [functionArn = {arn}]. Error message: FunctionUrlConfig exists for this Lambda function",1256 409,1257 "ResourceConflictException",1258 )1259 custom_id = md5(str(random()))1260 region = LambdaRegion.get_current_request_region()1261 url = f"http://{custom_id}.lambda-url.{region}.{LOCALHOST_HOSTNAME}:{config.EDGE_PORT_HTTP or config.EDGE_PORT}/"1262 # TODO: HTTPS support1263 data = json.loads(to_str(request.data))1264 url_config = {1265 "AuthType": data.get("AuthType"),1266 "FunctionArn": arn,1267 "FunctionUrl": url,1268 "CreationTime": timestamp(format=TIMESTAMP_FORMAT_MICROS),1269 "LastModifiedTime": timestamp(format=TIMESTAMP_FORMAT_MICROS),1270 "CustomId": custom_id,1271 }1272 if "Cors" in data:1273 url_config.update(cors_config_from_dict(data.get("Cors", {})))1274 lambda_backend.url_configs.update({arn: url_config})1275 response = url_config.copy()1276 response.pop("LastModifiedTime")1277 response.pop("CustomId")1278 return response, 2011279@app.route("%s/functions/<function>/url" % API_PATH_ROOT_2, methods=["GET"])1280def get_url_config(function):1281 # if there's a qualifier it *must* be an alias1282 qualifier = request.args.get("Qualifier")1283 arn = func_arn(function)1284 lambda_backend = LambdaRegion.get()1285 # function doesn't exist1286 fn = lambda_backend.lambdas.get(arn)1287 if not fn:1288 return correct_error_response_for_url_config(1289 error_response(1290 "The resource you requested does not exist.",1291 404,1292 error_type="ResourceNotFoundException",1293 )1294 )1295 # alias doesn't exist1296 if qualifier and not fn.aliases.get(qualifier):1297 return correct_error_response_for_url_config(1298 error_response(1299 "The resource you requested does not exist.",1300 404,1301 error_type="ResourceNotFoundException",1302 )1303 )1304 # function url doesn't exit1305 url_config = lambda_backend.url_configs.get(arn)1306 if not url_config:1307 return correct_error_response_for_url_config(1308 error_response(1309 "The resource you requested does not exist.",1310 404,1311 error_type="ResourceNotFoundException",1312 )1313 )1314 response = url_config.copy()1315 response.pop("CustomId")1316 return response1317@app.route("%s/functions/<function>/url" % API_PATH_ROOT_2, methods=["PUT"])1318def update_url_config(function):1319 arn = func_arn(function)1320 qualifier = request.args.get("Qualifier")1321 q_arn = func_qualifier(function, qualifier)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful