What are the caveats of running Laravel on AWS Lambda


Let’s set the scene. We’re looking for scaling a PHP
application. Googling around take us to find out that
AWS Lambda is the most scalable service out there. It doesn’t
support PHP natively, but we got https://bref.sh. Not only
that, we also have Serverless Visually Explained
which walk us through what we need to know to get PHP up
and running on AWS Lambda. But we have a 8 year old
project that was not designed from the ground up to be
serverless. It’s not legacy. Not really. It works well,
has some decent test coverage, a handful of engineers
working on it and it’s been a success so far. It just has
not been designed for horizontal scaling. What now?

Bref has two primary goals: Feature parity with other
AWS Lambda runtime (the Event-Driven layer) and also
to be a replacement for web hosting (the Web Apps layer).
In a way, with the Web App layer, Bref allows us to lift-and-shift
from our current hosting provider into AWS Lambda and have
PHP-FPM working the same way as we’re all used to love.
So if we just take a large codebase and redeploy it on
AWS Lambda, will everything just work?

Here are some caveats to pay close attention to help with
this journey.

30 seconds API Gateway Timeout

When deploying to AWS Lambda, it’s very common to use API
Gateway as the routing solution. It’s like an nginx for
our PHP-FPM, but completely scalable and managed by AWS.
It does come with a hard limit of timeout at 30 seconds.
If your application never takes longer to process any
HTTP request, then this is not a big deal, but if it does,
even if very rarely, API Gateway will kill the request.

If this is a deal-breaker for your application, a workaround
could be to use Application Load Balancer instead.

PHP Extensions

Not every PHP extension is available easily. Tobias Nyholm
maintains a great community project for PHP Extensions at
https://github.com/brefphp/extra-php-extensions. A lot of
great extensions are available by default
(as documented in https://bref.sh/docs/environment/php.html#extensions),
but if you need an extension that is not available by default
or not provided by Tobias, you’ll either have to build an
AWS Lambda layer yourself or you’ll have to find a way
without that extension.

Incoming Payload limit

When someone sends a HTTP request to your application,
they’re usually sending in some raw data with it, typically
on the body of the request. If the body of the request
goes above AWS limit, your code will never even be executed
and AWS will kill the request upfront. The limits
are currently as follows:

  • 1MB for Application Load Balancer
  • 10MB for API Gateway

A very big portion of use cases can fit in both of these
offerings. The most common use case that may pose a threat
is file uploads. If the file is bigger than the allowed
size, AWS will not accept the request. A common workaround
is to refactor the application so that the backend returns
an S3 Signed Url for the frontend to do the file upload
directly to S3 and then notify the backend once it’s done.
Without going into complex use-case, S3 can take 100MB
of upload in a plain and simple request, but it also
support multi-part upload with a much bigger limit.

HTTP Response Limit

AWS Lambda has a limit of 1MB for the Http Response. When
I started getting 502 Gateway Timeout due to large response
size, the workaround that worked best for me was to gzip
the Http Response. That brought down the response size
from 1MB to roughly 50~100kb. I never had to work on
a use-case where gzipped responses would be bigger than
1MB, so if you have such a case, let me know on Twitter
because I’m very interested in it!

AWS Lambda execution limit

AWS Lambda is capped at 15 minutes of execution. If you
use API Gateway, that’s capped at 30 seconds anyway, but
if you use Application Load Balancer, then it’s possible to
have Http requests going up to 15 minutes. Although that’s
not very common / likely to be useful, one thing that
does come up is background jobs. Sometimes they can go
above 15 minutes. One use case I worked on was importing
CSV file. The Http layer would return a Signed Url, frontend
would upload to S3 and notify the backend of a new file
ready for processing. A message for SQS would be produced
and a new AWS Lambda would pick up the message as the worker.
Downloading the CSV file from S3 and processing each row
individually could take more than 15 minutes. The way
I handled that was to create a recursive Job. What I did
was:

  • Download the file from S3
  • Process 1k rows on the file (for loop)
  • Each row processed increments a record on the database
  • Produce a new SQS message IDENTICAL to the one currently being worked on
  • Finish the job successfully

With this approach, the SQS message that gets picked up will
finish before 15 minutes and it will produce a new SQS message
with the exact same work unit. The job can always load
the pointer from the database to know where it left off
(the starting point of the for loop). If we don’t have 1k
records to run through, we can stop producing SQS messages
because we reached the end of the file. If there are
still rows to be processed, the new IDENTICAL SQS message
will make a new Lambda start, which means another 15 minutes
limit.

5 Layers per function

If your project uses too many exotic PHP extensions, you
may end up hitting the limit of 5 layers per function.
Bref itself will consume 2 of 5 layers. Each extension
is a separate layer. If you need, e.g., GMP for verifying
JWT tokens, Imagick for image processing and Redis, you’ve
reached your limit and the next extension you need might
be problematic.

50 MB of zipped Codebase / 250 MB of unzipped codebase

Your project source code cannot have more than 50MB of
zipped content or 250MB of unzipped. The 250MB unzipped also
include the Lambda layers extracted into your Lambda environment.
It sounds like a lot of code, but there are some PHP packages
out there that put binaries on your vendor folder which
may take a lot of space. There are some workaround
documented by Bref which involves zipping your vendor,
uploading it to S3 and deploying your code without
the vendor folder. The vendor then gets downloaded
on-the-fly when your Lambda starts. It adds a little
bit of overhead on your cold-start but overcome AWS
limitation on the codebase size.

read-only file-system

The entire file-system on AWS Lambda is read-only with
the exception of /tmp. Any process that is writing
files into disk will need tweaking to work with the temporary
folder. Furthermore, two different requests will not be
guarantee to hit the exact same Lambda, so relying
on local disk is not a safe bet. Any data that
may need to be accessed in the future must go to S3
or a durable storage.

500MB on /tmp

Another thing to keep in mind is that /tmp only has
500MB of disk space. If you fill that up, the Lambda environment
will start to get errors for full disk.

SQS messages cannot have more than 256kb of payload

Maybe on your server you use Redis as the Queue Storage
for your background jobs. If your serialized job class
has more than 256kb, it will not fit into AWS SQS.
A common workaround is to pass to the job a reference
to something big instead of the big thing itself.
For instance, if you have a job class that takes a collection
of 1 million rows of a database, that can be mitigated
by passing the instructions to query the database instead.
An SQL Query would be extremely small and produce a somewhat
similar result.

Every-minute CRON

When you have a server, putting a CRON to run every
minute and doing some clean up or tidy-up tasks sounds
trivial. But since AWS Lambda charges per code execution,
having a CRON running every minute can add up a bill
and/or be an unwanted side-effect. AWS offers
Scheduler for AWS Lambda, which means code can still
run on a regular basis, but it’s important to keep in
mind that everytime Lambda starts, it adds up to your
bill. Things like cleaning up old/stale files might not
even be necessary since every request may hit a clean
AWS Lambda environment.

Conclusion

This may not be an extensive list of gotchas, but I tried
to include everything that I may have faced while working
with AWS Lambda for the past 3 years. A lot of these limitations
have acceptable workarounds and overall hosting a Laravel
application on a single fat AWS Lambda has brought more
benefits than problems, so I would still advise in favour
of it if you’re looking to scale and ditch server maintenance.

As always, hit me up on Twitter with any
questions.

Cheers.

Laravel News Links

FDA greenlights over-the-counter hearing aids

Over-the-counter hearing aid sales should soon become a practical reality in the US. The Food and Drug Administration has issued a final rule allowing the sales of hearing aids for mild-to-moderate impairment without requirements for exams, prescriptions or audiologist fittings. The measure is expected to take effect in mid-October, when you should see aids reach physical retail stores.

You’ll still need a prescription for severe hearing loss, or for anyone under 18. The FDA has also set design and performance requirements for over-the-counter aids, and has tweaked rules for prescriptions to ensure "consistency." The definitive rule comes in response to public and industry feedback, including lower maximum sound output, a requirement for user volume control and canal depth limits.

Congress first passed laws requiring over-the-counter hearing aids in 2017 in a bid to lower healthcare costs, improve access and spur competition. In theory, you would see more people wearing the devices as access and technology improve. However, the FDA didn’t propose the necessary rule to fully implement the wearables until October 2021.

It could be awhile before there’s a wide range of choices, but there are already offerings here or in the works. Lexie, for instance, recently began selling the $899 B1 using technology from Bose’s reportedly defunct hearing aid division. Companies like Jabra have also leaped in early. The prices aren’t trivial, but they’re relative bargains when aids have historically cost thousands of dollars before insurance.

Engadget

Uintah Precision Modern Sporting Muzzleloader

https://www.thefirearmblog.com/blog/wp-content/uploads/2022/08/Uintah-Precision-Modern-Sporting-Muzzleloader-1-180×180.jpg

Uintah Precision Modern Sporting Muzzleloader (1)Uintah Precision, a company primarily known for making bolt action AR uppers and complete firearms, has entered the muzzleloader market. However, what they make is not your great-great-grandfather’s muzzleloader. The new Uintah Precision Modern Sporting Muzzleloader can be easily mistaken for one of their AR bolt guns, but if you look closely, you’ll notice a ramrod […]

Read More …

The post Uintah Precision Modern Sporting Muzzleloader appeared first on The Firearm Blog.

The Firearm Blog

Root extract may treat type 2 diabetes

https://www.futurity.org/wp/wp-content/uploads/2022/08/type-2-diabetes-1600.jpgA Rhodiola rosea plant with green leaves and yellow flowers in growing in dark soil.

An extract from the roots of the Rhodiola rosea plant might be effective for helping manage type 2 diabetes, according to a new study.

The extract shows promise as a safe and effective non-pharmaceutical alternative, the researchers report.

They found that, in a mouse model of human type 2 diabetes, Rhodiola rosea lowered fasting blood sugar levels, improved response to insulin injections, modulated the composition of bacteria in the gastrointestinal tract, and decreased several biomarkers of inflammation.

“The prevalence of type 2 diabetes and the associated health costs have risen steadily in recent decades. Humans have used plants and natural products for thousands of years to treat diseases, and our study shows Rhodiola rosea is a good candidate for further investigation,” says Mahtab Jafari, professor of pharmaceutical sciences at the University of California, Irvine, and corresponding author of the paper in Scientific Reports.

“Current treatment recommendations include lifestyle changes as well as oral and intravenous medications. However, these drugs have significant limitations or side effects, increasing the need for new therapeutic interventions.”

The team used a genetically engineered mouse model that develops obesity, insulin resistance, and high blood sugar, similar to advanced human type 2 diabetes, to test whether Rhodiola rosea could improve glucose homeostasis.

In the study, cohorts of age-matched male and female mice were randomly assigned to one of two groups: control, which received water, or experimental, which were administered Rhodiola rosea extract.

“Our findings suggest that Rhodiola rosea might be beneficial for treating type 2 diabetes, acting through changes in the microbiome that result in increased gut barrier integrity and decreased translocation of inflammatory molecules into the blood circulation,” Jafari says.

“Gut barrier integrity influences body weight and insulin response, and this botanical product may improve the responses of liver and muscle tissues to insulin produced by the pancreas.”

The team’s next steps are to perform a larger follow-up study in a different mouse model of obesity-induced diabetes to confirm these findings and to investigate the molecular mechanisms involved. Ultimately, Jafari hopes to conduct Rhodiola rosea clinical trials in patients with type 2 diabetes.

“Our research presents a solid case for the importance of conducing high-quality pre-clinical studies based on sound methodologies to evaluate the efficacy of standardized plant extracts. We have set the stage for human clinical studies, with the ultimate goal of improving health outcomes for type 2 diabetes patients,” Jafari says.

Additional coauthors are from Brigham Young University and UC Irvine. The UCI School of Medicine-Pharmaceutical Sciences Collaborative Research Funds and John P. and Lois C. Wareham funded the work.

Source: UC Irvine

The post Root extract may treat type 2 diabetes appeared first on Futurity.

Futurity

Watch: Dude who’s wanted for murder calls cops over cold McDonalds fries, winds up tased

https://www.louderwithcrowder.com/media-library/image.png?id=30835904&width=980

Everyone one of you reading this has had a bad fast food experience. Orders are wrong. Food isn’t cooked the way you want. It looks nothing like the photo. We’ve all had these first-world problems. But we don’t get so angry we call the cops. Nor do we get so angry we forget we are wanted for murder before calling the cops. Antoine Sims was that angry, and he’s not loving it.

Not while screaming like a little girl after getting tased. After running from the cops. After realizing maybe calling them wasn’t one of his better ideas.

Antoine Sims is now in the lead for dumbest criminal of 2022. Third place is the guy who tried robbing a jewelry store in broad daylight, only he lacked the upper body strength to break glass. Second place is a man who almost got away from the cops if a traffic post didn’t get in his way. Sims just rocketed up the charts.

The details of why he was wanted are horrible. Sims and some other loser are accused of setting fire to a car with a woman’s body inside after a botched drug deal led to a gunfight. He failed to appear for a 2018 court date over it.

It all explains why Sims would call the cops over his cold french fries and then say he was afraid of the cops when they showed up. Somewhere between telling the cops, “I try the fries the fries, they’re lukewarm but they’re not hot," and yelling as a sudden jolt of electricity runs through his body, Antoine realized his tactical era.

All over french fries. Overrated french fries, too.

The Louder with Crowder Dot Com Website is on Instagram now! Follow us at @lwcnewswire and tell a friend!


Giga-Chad Traffic Pole VAPORIZES Criminal! | Louder With Crowder

youtu.be

b’Louder With Crowder’

Everything You Need to Know to Start Writing Bash Programs

https://static1.makeuseofimages.com/wordpress/wp-content/uploads/2022/08/photo-of-a-command-line-interface-.jpg

Bash scripts come in handy for automating tasks, and you’ll find they’re great for building simple command line applications. The Bash shell interprets Bash scripts, so you won’t need to install any dependencies to write and run them. Bash scripts are also portable since most Unix-based operating systems use the same shell interpreter.

Knowledge of Bash scripting is a must for every developer, especially if you work with Unix-based systems.

Variables in Bash

Bash variables are case-sensitive. To declare variables, use an equals sign (=) with the name on the left and value on the right:

STATE=Washington

The value this declaration assigns to STATE is a single word. If you need spaces in your value, use quotes around it:

STATE="North Arizona"

You’ll need to use a dollar sign ($) prefix to reference variables in other variables or statements:

STATE=Washington
LOCATION="My Location is $STATE"

Printing Values in Bash

There are several ways you can print variables in Bash. You can use the echo command for basic output or the C-style printf command for string formatting.

STATE=Washington
LOCATION="My Location is $STATE"
echo $LOCATION

After declaring the STATE variable, this script defines LOCATION by referencing STATE. If then uses echo to print the final value of the LOCATION variable.

The printf keyword allows you to use formatting verbs to output data. The string formatting verbs are similar to the ones in C and Go but with limited verbs.

Verb Functionality
%c prints single characters
%o prints Octadecimals
%s prints strings, independent of casing
%x prints lowercase hexadecimal
%X prints uppercase hexadecimal
%d prints integers
%e prints scientific notion floats in lowercase
%E prints scientific notion floats in uppercase
%f prints floating point numbers
%% prints a single percentage symbol.

Here’s an example of using a verb with the print keyword.

STATE=Lagos
printf "My Location is %s" $STATE

The printf function would substitute the STATE variable in the position of the %s verb, and the output would be “My Location is Lagos”.

You can make comments in Bash with the hash or pound (#) symbol. The shell automatically ignores comments.

#!/bin/bash


There are no multi-line comments. Most IDEs and text editors allow you to comment with the Ctrl/Command + forward slash(/) shortcut. You should be able to use the shortcut to create multiple single-line comments.

Receiving User Input in Bash

Like many other programming languages, you can receive user input in Bash to make your programs/scripts more interactive. You can use the read command to request the user’s input.

read response

In this case, the response variable will hold the user’s input on delivery.

echo "What do you want ?: "
read response
echo $response

The user input request will be on a new line in the example above.

You can add the -n flag to the echo print statement to retain the line where the user enters input.

echo -n "What do you want."
read response
echo $response

Declaring Arrays in Bash

Arrays in Bash are just like most languages. You can declare an array variable in Bash by specifying the elements in parentheses.

Countries=('USA' 'Russia' 'Ukraine', "England", "Taiwan", "China")

Accessing an array via reference to the variable name would fetch the first element. You can access the entire array by using the asterisk sign as the index.

echo ${Countries[*]}

You can also specify the index of the array to access a specific element. The index of an array starts at zero.

echo "${Countries[4]}"

Conditional Statements in Bash

Bash provides conditionals for decision-making in programs.

Here’s the anatomy of an if-else statement in Bash. You’ll have to use the semi-colon to specify the end of the condition.

if [[ condition ]]; then
echo statement1
elif [[condition ]]; then
echo statement2
else [[condition ]]; then
echo statement3
fi

You must end every if statement with the fi keyword.

if [ 1 == 2 ]; then
echo one
elif [ 2 == 3 ]; then
echo two
else [ 4 > 3 ];
echo "correct, 3"
fi

You can use case statements in your Bash programs using the case keyword. You’ll have to specify the pattern followed by ending parentheses before the statement.

CITY=Lagos
case $CITY in
"Washington")
echo "United States of America"
;;
"Lagos" | "Abuja")
echo "Nigeria"
;;
"Johannesburg" | "Cape Town")
echo "South Africa"
;;
*)
echo "Antarctica"
;;
esac

You can define the default case using the asterisk (*) sign as the pattern. Case statements must end with the esac keyword.

Loops in Bash

Depending on your needs, you can use a while loop, range for-loop, or a C-style for loop for recurring operations.

Here’s an example of the C style for-loop. For-loops must end with the done keyword, and you must end the for statement with a semicolon followed by the do keyword.

for ((a = 0 ; a < 10 ; a+2)); do
echo $a
done

The range for loop comes in handy for working with files and many other operations. You’ll need to use the in keyword with the range for-loop.

for i in {1..7}; do
echo $1
done

Here’s a simple infinite loop to demonstrate Bash while loops in action.

name=1
while [ 1 -le 5 ]
do
echo $name
done

The -le in the condition statement is the binary operator for less than.

Functions in Bash

You don’t need keywords to declare functions in Bash. You can declare functions with the name and then parentheses before the function’s body.

print_working_directory() {
echo $PWD
}
echo "You are in $(print_working_directory)"

Functions can return variables in Bash. All you need is the return keyword.

print_working_directory() {
return $PWD
}

The print_working_directory function returns the working directory of the file.

You Can Write Shell Scripts in Other Languages

Bash isn’t the only language you can use to interact with your operating system’s shell or build command-line applications. You can use many other languages like Go, Python, Ruby, and Rust.

Many operating systems have Python3 pre-installed, and Python is a prevalent language. If you need even more functionality than Bash scripts can offer, consider using Python.

MUO – Feed

Woox Thunderbird Throwing Axe

https://www.ammoland.com/wp-content/uploads/2022/08/WOOX-AXE-500×333.jpg

Axe throwing has become a popular sport. If you want to get into it, check out the WOOX Thunderbird Throwing Axe. IMG Tom Claycomb

U.S.A. -(AmmoLand.com)- As soon as I received a Press Release from Chip Hunnicutt about the WOOX throwing axe I knew that I had to check one out. So, long story short-before long I was throwing a WOOX Thunderbird Axe at a dead tree in the backyard. I’ve messed around on a small-time basis with throwing knives. Years ago I met a girl that was the knife throwing queen with a major knife company at the SHOT Show. She was really good and the traffic at her booth was slow so she took some time and worked with me a bit. I learned quite a bit from her.

I’m not a knife-throwing expert but from what I can tell, here are the basics. It is imperative to release the knife at the exact same spot every time. You can’t release it one time with your arm fully extended and the next time with your elbow half bent. Or else one time, the knife will hit on its point and the next time on the end of the handle.

The next big pointer. If your knife hits the target on the hilt of the handle, then you need to either step backwards or forwards, which will correct the point of impact. So really, in a nutshell, it is that simple.

Now let’s switch gears and jump into axe throwing. I like throwing an axe more because since it has a convex cutting edge, it has a larger sticking surface. So even if my throw isn’t dead on it is more likely to stick.

I’m not a competition axe thrower by any means, but by chance, this week, I was over in South Dakota and noticed that there is an axe throwing facility named Hub City Axe Throwing located in the Aberdeen mall. In a short amount of time, I was meeting with the owner Ryan Perrion. He is #75 in the WATL (WORLD AXE THROWING LEAGUE). There are two major leagues. The other one is IATF (INTERNATIONAL AXE THROWING FEDERATION). When covering a topic that I’m not well versed in, I interview an expert. In talking to Ryan, here are a few insights he shared.

  1. He affirmed what I stated above that due to the convex edge, an axe is a little easier to stick than a knife.
  2. He demo’d how important it is to throw from the exact same distance every time. He threw and had a marginal stick. Then he stepped back 6-inches further and threw with the exact same form. Solid stick. It was amazing how much of a difference that 6-inches made.
  3. He suggested when getting an axe, be sure to get one that fits you. Look for the proper weight, handle size and length of handle that fits you personally. And if you plan on throwing competition, different leagues have different axe specs, so buy accordingly.
  4. In competition they throw from 10 feet and 15 feet.

I don’t foresee myself doing competition axe throwing, but it was interesting talking to Ryan, and I learned a lot from him. So, if you’re interested in axe throwing competitions, check and see if there is a venue near you. Or, more likely, you’re like me and would just like to throw one and mess around. When you’re up in the mountains camping, you need to have some activities for everyone to do when lounging around camp. I think it’d be fun to set up a log to throw at. Or you could cut a wafer out of a log and spray paint some circles on the end and throw at that. That’d be a great way to pass time in camp.

So I think throwing a WOOX Thunderbird Axe could be great fun while hanging out in camp. In another few weeks, I’ll have an elk camp set up in the mountains for the archery season. I think it’ll be fun getting to practice more with my new WOOX Thunderbird Throwing Axe. Who knows, my next article may be on how I filled my elk tag with my new WOOX Thunderbird Throwing Axe. I can’t be much worse of a shot with it than I am with my bow!

So grab a WOOX axe and see if you can pick an apple off of your mother-in-law’s head. The MSRP on the WOOX Thunderbird Axe is $69.00. it is offered in purple, orange, blue or black. According to Ryan they make some decent axes. I’d recommend you also get the leather sheath for $29.00, and as is usual, we will close with the company comments.

The Thunderbird from WOOX is a dedicated axe for throwing, featuring a lightweight head for more accuracy and precision. The tomahawk style is just as home as a one-handed wood cutter for those times when you need to make quick work of chopping projects.

The 14” handle is real American Appalachian hickory and the Italian tempered carbon steel head comes in your choice of four distinct colors, perfect for teams or distinguishing singles competition throwing. The Thunderbird meets ALL the National and International competition requirements (WATL & IATF).

Thunderbird accessories:

– Sheath – protect your sharp edge and prevent unintended cuts
– Whetstone Puck – maintain your Thunderbird’s edge with this dual grit whetstone


About Tom Claycomb

Tom Claycomb has been an avid hunter/fisherman throughout his life as well as an outdoors writer with outdoor columns in the magazine Hunt Alaska, Bass Pro Shops, Bowhunter.net, and freelances for numerous magazines and newspapers. “To properly skin your animal you will need a sharp knife. I have an e-article on Amazon Kindle titled Knife Sharpening for $.99 if you’re having trouble.”

Tom Claycomb

AmmoLand Shooting Sports News