An exploration of Apple business news and technology. We talk about how businesses can use new technology to empower their business and employees, from Leo Dion, founder of BrightDigit.
[00:00:00] Understanding AWS Lambda and Serverless Computin
---
[00:00:00] Leo Dion (host): Hey folks, happy Thanksgiving. To those of you in the us I just wanted to let you know that we have a big Black Friday sale right now on both Bushel and Patreon membership. You can click a link to the newsletter below in the show notes.
[00:00:13] Leo Dion (host): Definitely take a look. It's 50% off bushel membership for a year and 25% off Patreon membership. So if you want early access to episodes like this, , this is definitely something you wanna take advantage of. There is a code, the code is 6 4 6 3 2 . So, yeah, , join the Patreon membership to get early access to episodes and take advantage of the 50% off on bushel.
[00:00:36] Leo Dion (host): This will only be available for the next few days, so definitely take a look and I hope you enjoy this wonderful episode with Sebastian. Bye everybody. I.
[00:00:47] Leo Dion (host): Welcome to another episode of Empower Apps. I'm your host, Leo Dion. Today I'm joined by Sebastian Storm Mock. Sebastian, thank you so much for coming on.
[00:00:57] Sébastien Stormacq (guest): Thank you, Leo, for having me.
[00:00:58] Leo Dion (host): So good to see you at the Server Site Swift Conference, and excited to have you on today to talk about. Amazon and AWS Lambda. But before we get into that I'll let you go ahead and introduce yourself.
[00:01:13] Sébastien Stormacq (guest): I am working at AWS since 12 years. I start writing code like 40 years ago. It was on a Commodore 64 first time. So I have a couple of white hairs. I love to write
[00:01:24] Leo Dion (host): Load star eights commas one right.
[00:01:28] Sébastien Stormacq (guest): Different systems, different programming language. I'm very curious about programming language. And I fall in love with Swift yeah, at the very beginning, almost 10 years ago when they released the first beta version.
[00:01:39] Sébastien Stormacq (guest): I host a podcast. I'm talking with developers most of the time, writing blog posts, doing a bit of video. That's my day-to-day activities.
[00:01:48] Leo Dion (host): So you're kinda like a developer evangelist, basically. Is that a good way to put it? And then, is your primary focus swift at AWS or just Lambda, or what specifically?
[00:02:03] Sébastien Stormacq (guest): that's a good question. My primary focus is writing blog posts to announce new services and new feature. We are writing a lot right now because we have our customer conference that happened first week of December at Reinvent. I'm also the producer of two AWS podcast, but on my side and, I have one or two days per week on my side where I can focus on something else. And I'm trying to, to bring the swift developer community to the cloud and try to bridge the gap to make it easier for a swift developer to deploy their application in the cloud. And as part of that, I'm working with the SWIFT server working group.
[00:02:36] Sébastien Stormacq (guest): So we have daily meetings with different person from the SWIFT organization at Apple and other members of the SWIFT community and the open source SWIFT community.
[00:02:45] Leo Dion (host): Yeah. And we had a episode with Yanas on a
[00:02:47] Leo Dion (host): Months ago talking about the server side working group. So where did you say that conference was? In December.
[00:02:56] Sébastien Stormacq (guest): Las Vegas Never Nevada.
[00:02:58] Leo Dion (host): Okay.
[00:02:59] Sébastien Stormacq (guest): In first week of December,
[00:03:01] Leo Dion (host): Yeah, hopefully it'll be nice and warm. Yeah, so let's get into it. So a lot of folks who are swift developers surprise are iOS developers and may not know a lot about the server.
[00:03:14] Leo Dion (host): We talked about this previously. In the episode I had with Bit Boag on, it's not really something like if you probably looked at the pie chart of SWIFT developers. AWS Lambda very big, vast majority would be. Yeah, exactly. So explain, I think most people know kind of what a server is, but what exactly does that mean?
[00:03:35] Leo Dion (host): Serverless, and what is a, what does Lambda actually do?
[00:03:39] Sébastien Stormacq (guest): I'll come to that in, in a minute, but just about Swift because you said the majority of the developers are coming from iOS and that's true. We also observe another group of developers on swift, the ones that choose to use SWIFT for the quality of the language, for the low memory footprint, for the very strict.
[00:03:55] Sébastien Stormacq (guest): The type system, the very developed concurrency, especially now with swift six. So that programming language has a lot of benefits to do development on the server side and not only on the client side to develop your API, for example, or your batch processing, your image processing, document processing on the server side.
[00:04:13] Sébastien Stormacq (guest): And then as a Swift developer, you start to write code. There is that huge ecosystems of libraries, driver for database and things like that. And then you wonder, okay, where I'm going to deploy that code. And of course it runs on your laptop. Maybe it runs on a container. Then you start, okay, how can I host a container somewhere?
[00:04:30] Sébastien Stormacq (guest): Maybe I should rent a virtual private server. And this is where I enter and say, Hey, maybe you can deploy on AWS as well, because we have virtual machines, we have containers. There is that options that we are here to talk about today called AWS Lambda. So Lambda is not new. It's something that exists in 10 years.
[00:04:50] Sébastien Stormacq (guest): We are celebrating the 10 years of AWS Lambda this year, November, 2024. What is Lambda? Lambda? It's a function as a service. FAAS if you like, acronyms. So the idea of Lambda as a developer, I write code and then I just publish my code to Lambda and I don't have to care about what is the infrastructure that will be deployed to run that code.
[00:05:15] Sébastien Stormacq (guest): I don't have to care about virtual machines installing a a runtime, installing, I don't know, libraries. I don't. Need to think in terms of deployments, scaling my infrastructures, we have at least two machines with redundant in case one goes down or to scale to 1 million requests per hour and have a load balancer and things like that.
[00:05:37] Sébastien Stormacq (guest): Lambda, the service a s Lambda will do?
[00:05:39] Sébastien Stormacq (guest): that for me as a developer. I write my code, I.
[00:05:42] Sébastien Stormacq (guest): click publish. The code is exposed on the internet or not, depending on how you configure things. And that code will run inside micro virtual machines. It's not a container, it's a micro vm, and the service will scale that automatically up.
[00:05:58] Sébastien Stormacq (guest): So if you have 1000 call per second, thank you, congrats. You have a very successful application, but you don't need to be wake up in the middle, middle of the night because there is no more space on your virtual machine or whatever. The system will scale automatically, but it will also scale down to zero.
[00:06:13] Sébastien Stormacq (guest): If your app is not used, then the last micro VM is shut down. A new one will be restarted. If a new request come from your for your code, but it means that you stop paying for that as well. And that's very interesting because you just pay what you use. So for very small application for test and dev, it almost cost zero, zero
[00:06:36] Leo Dion (host): So you say it's like a micro vm. How is that different from say a docker container that just runs your code?
[00:06:44] Sébastien Stormacq (guest): The main difference, it's the level of isolation between different containers from multiple customer. At AWS, our first priority is the security. So when we launched Lambda two 10 years ago we, of course we didn't want that your code?
[00:06:58] Sébastien Stormacq (guest): inside. Lambda function is able to see or to manipulate the memory from another customer running another Lambda function on the same machine.
[00:07:06] Sébastien Stormacq (guest): So at the very beginning, we create different virtual machines to host all these Lambda function, one virtual machines or multiple virtual machine for one customer. And we were not sharing the underlying virtual machines between customer to have very strict. Isolation of your programming environment.
[00:07:25] Sébastien Stormacq (guest): And we cannot do that with Docker because as you know, two docker containers are running on the same machine, on the same kernel. There is only one operating system, so a micro vm it's a vm, but with just the minimal amount of libraries that, that we need to run a piece of code that is totally isolated from other micro VM on the same bar metal.
[00:07:46] Sébastien Stormacq (guest): Hardware, and that's the technology we are using for Lambda. It's open source, it's called firecracker. You can find it. Just try a firecracker on GitHub and you will find it's a rest base micro VM technology.
[00:07:58] Leo Dion (host): Okay, so when you say it's serverless, how do I then hook up something like a database because it's nice to run a function, but what if I wanna store something, for instance, some sort of data, then what am I gonna do? Because there is no server.
[00:08:16] Sébastien Stormacq (guest): So when I say serverless, of course there are server at the end of the day that code needs to run somewhere. The key point with serverless is that I, as a developer, don't have to manage this server. I don't have to install Linux to. Patch it to install. I dunno if it's Java Code, Java virtual machines, or if it's SWIFT code or Swift Runtime.
[00:08:34] Sébastien Stormacq (guest): This is managed by Ws, so I don't have to do that. That's the first thing. Then typically your Lambda function alone is not very useful. As you mentioned, you need something upstream to call to involve the land function, and you need something downstream. The Lambda function can call to fetch data.
[00:08:51] Sébastien Stormacq (guest): It might be files on the stream. It might be a Postgres database or no SQL database somewhere. So let's start with the flow. What will invoke your Lambda function? Most of the time it'll be another AWS service. So if you want to develop a rest, API, for example, you will put in front of your Lambda function.
[00:09:09] Sébastien Stormacq (guest): An API gateway. So the API gateway, it's like a web server. It's the HT TPS termination point that will receive your gate, put post HGTP request and will invoke your Lambda function where you will handle these these requests. So you will receive in the Lambda function, all the parameters, the H TT P headers and stuff like that.
[00:09:28] Sébastien Stormacq (guest): And then you really respond with an HTT P response as well. It might be you might use Lambda function to react. On something that happens in your infrastructure. If you have a NoSQL database in the cloud called DynamoDB, you can have lambda functions that are trigger. So something change in my database and it triggers a Lambda function just like the old Oracle trigger.
[00:09:50] Sébastien Stormacq (guest): If you remember from the time you were using relational database, it's the same id except. It's different processes. Here. It might be a file arriving on Amazon three. You know, you drop a file on a three, it triggers the Lambda function that will process that file, maybe summarize it, chunky, recode it, move it, whatever.
[00:10:08] Sébastien Stormacq (guest): So that's what can invoke your Lambda function. And then inside your code in the Lambda function, you do pretty much what you want. If you need to connect to a database, you take a database driver, JDBC, or DBC In Swift, we have a database driver from MongoDB for Postgres, for MySQL, and it's code as usual.
[00:10:28] Sébastien Stormacq (guest): You connect to the IP address or the DNS name of the database. You. Enter credentials, use on EM password and send your s QL statement over database. The only thing which is a bit different with Lambda, remember, I, I told you if the, if there is no more call to your function, AWS Lambda will terminate the last micro vm.
[00:10:48] Sébastien Stormacq (guest): So whenever a new call will, will come, we'll recreate a micro vm. Reinstall the Lambda function and. If you use relational database, you need to reopen the connection to your, the TCP connection to your database. That's pretty much it. The only things you have to think about is that maybe your VM will be terminated at some point.
[00:11:10] Sébastien Stormacq (guest): So anything which is persistence need to be rein stances when the code start again.
[00:11:16] Leo Dion (host): Yeah. So I've actually, we, I think we've talked about this previously, but I've actually built an AWS Lambda in Swift used Dynamo key manager. Gosh, I don't know how many Amazon services, but it was like an interesting experience. Like one of the things that yeah, you have to kind of realize.
[00:11:37] Leo Dion (host): And this was completely like, no, no vapor, no hummingbird, we'll talk about later. This is completely all through AWS Lambda. Was that yeah, you have to deal with the fact that sometimes connections could have been shut down and you have to handle that yourself. And I like that you mentioned, 'cause obviously here we're gonna be talking about like rest APIs, which is like a majority, but there are
[00:11:58] Sébastien Stormacq (guest): cases. Yeah.
[00:11:59] Leo Dion (host): Right.
[00:12:00] Leo Dion (host): But there are like a lot of other instances and triggers that you'll want to deal with. And so I'm really glad you mentioned that.
[00:12:07] Getting Started with AWS Lambda in Swift
---
[00:12:07] Leo Dion (host): So if you were to like get started with AWS Lambda, would you suggest just going with the, with 'cause So it'd be like, what, five years ago that I worked on this.
[00:12:17] Leo Dion (host): So I. don't know how much has changed. Probably a lot. But would you just go with like AWS Lambda or would you build on top of something like coming bird birder vapor that. That builds through, and I'm not totally clear if that's still available or how that works, or if you're gonna start a server how would you go about doing that like today for a beginner?
[00:12:38] Sébastien Stormacq (guest): First I would go serverless. I would eliminate all deployment options that require some kind of machine, either Docker container or micro virtual machines running 24 by seven. Because especially when you're a student, when you're a beginner, when you're, exploring a new id, you don't know if it's going to work or not.
[00:12:56] Sébastien Stormacq (guest): So it's not necessary to engage a budget to have a machine running 24 by seven and to manage that machine. So serverless is probably the way to go. Question is should I use I. Web framework such as Vapor and Hummingbird on Swift or go directly native on Lambda. It's possible as well to write code swift code specifically for Lambda.
[00:13:16] Sébastien Stormacq (guest): I would say, I'm sorry, that's my solution architect type of answer. I. It depends. It depends on your budget, depends on your needs. But there is one overlap. So if you start with Hummingbird and Vapor these two frameworks have an HTTP server built in. So these things can accept and will accept an HTTP request with get post and then wrote that request to the specific handler in your code.
[00:13:38] Sébastien Stormacq (guest): And the thing I described just before API gateway. The Lambda function is the same. It's an HTT PS endpoint that will look at the HTTP parameter and route the call to a specific Lambda function. The way I see it if you have already existing code using Hummingbird and Vapor, you can deploy that application.
[00:13:56] Sébastien Stormacq (guest): As is on Lambda, and both Vapor and Hummingbird have a small adapter lambda adapter that will marshal the arguments between whatever format they receive from the API gateway and pass that in a way that the, framework hummingbird or vapor understands. So it's a very tiny,
[00:14:13] Leo Dion (host): how does it
[00:14:14] Sébastien Stormacq (guest): one line change.
[00:14:16] Leo Dion (host): Well, how does it pass the H? Like how do, this is a totally technical question. Sorry. But like how does it pass the route? Is it like a JS and then it has to like decode the JS N of whatever route was passed in. Okay.
[00:14:29] Sébastien Stormacq (guest): Yeah. in that case, the HTT P request arrive on the API gateway. The API gateway will look at all the HTT P there, the parameters and things like that will create a big JSON with all that information And invoke your Lambda function with
[00:14:41] Leo Dion (host): And so that's what this vapor plugin or hummingbird
[00:14:44] Sébastien Stormacq (guest): Exactly what they do is read that json for you and then recreate something that's the native hummingbird of vapor framework. I can understand the advantage of doing that. It's one or two lines of code to change in your code. No more than that. Add dependency to the vapor adapter or the hummingbird adapter.
[00:15:03] Sébastien Stormacq (guest): And you can have what we call a monolith lambda. It's. Speak Lambda function that handle all the case, the get, the post, the delete the connection to the database and things like that. And it's perfectly valid because you don't need to change your code. So why would you do that? It's to reduce your cost.
[00:15:19] Sébastien Stormacq (guest): You don't have to run a container 24 by seven or a virtual machine 24 by seven if you have an application, which is. Invoked a couple of times per minute, a couple of times per hour with downtime during the night, for example, or during the weekend. Moving from a container or virtual machine will reduce your cost.
[00:15:37] Sébastien Stormacq (guest): If you.
[00:15:38] Sébastien Stormacq (guest): go to Lambda,
[00:15:39] Leo Dion (host): Okay.
[00:15:39] Sébastien Stormacq (guest): it's not always true If you have an application which is under. Constant load that receive a stream of request 24 by seven and consume a lot of CPU Lambda might be more expensive than a Docker container on micro vm. So there is a sweet spot to find in terms of pricing. But for the huge majority of the use cases, Lambda is less expensive than a 24 by seven virtual machine.
[00:16:01] Leo Dion (host): Why would you put, so is there ever an advantage, like I'm just thinking like, if you had one route, like at that point, like what would be the point in having Hummingbird or Vapor? 'cause then you could just handle
[00:16:15] Sébastien Stormacq (guest): Now I. start saying, if you have existing code with Hummingbird and Vapor, Then you can migrate them with minimal change if you start from scratch. But maybe you can say, I'm biased because I'm working for AWS, so. If I start from scratch, I will go directly to the native Lambda. So an API gateway that does the HT TPS termination and a native Lambda functions.
[00:16:36] Sébastien Stormacq (guest): So we have developed in open source apple started that project. It's maintained by the community now, the Swift AWS Lambda runtime that allows to Right?
[00:16:45] Sébastien Stormacq (guest): swift function for Lambda. And to deploy. Yes. The public version on the Swift server GitHub report, it's five years old, but we had different prototype experience that were driven by different members of the community before.
[00:17:00] Leo Dion (host): Right, right, right. What was I gonna say? Dang it. I forgot.
[00:17:04] Sébastien Stormacq (guest): it happens to me too.
[00:17:05] Leo Dion (host): I know. Really, I. That's what editing is for. Ado Lambda.
[00:17:10] Sébastien Stormacq (guest): Deploying Hummingbird versus Native Lambda.
[00:17:13] Sébastien Stormacq (guest): function.
[00:17:14] Leo Dion (host): Well, let's ask the next question so you can answer this in whatever way you want to, but how portable is a Lambda if, for instance, I don't want to like, I'm sorry. Like, you know, I might not wanna stick with Amazon forever. I might find some other service.
[00:17:33] Sébastien Stormacq (guest): Of course. And Lambda is not the only function as a service. available out there. Google has Google function. I think there is something on Microsoft as well. Azure. So yes the portability is an important question. There is no vendor looking. I don't like the word vendor looking.
[00:17:48] Sébastien Stormacq (guest): I'm talking about a cost to exit it. Going out will cost you something more or less depending on your architecture, your code. So, le let's think about it. It really depends on how you architecture your code. If the lambda specific part, so the parameter that you function.
[00:18:06] Sébastien Stormacq (guest): And the message that it'll produce as an output if this is well isolated from the rest of your code. The cost of exit is really low because your Lambda function can be quite minimal. And all the business logic is inside reusable libraries. So if you segment your code, if you architecture your code correctly, you have just the entry and the exit point to to rewrite.
[00:18:26] Sébastien Stormacq (guest): Of course, on top of that, you have, and to be honest, you have also the deployment procedure, You are most likely going to write. Scripts or infrastructure code to deploy this lambda function. And the monitoring, you probably want some alerting if you have an error rate that goes up or if you have too many concurrent invocation or any type of errors.
[00:18:45] Sébastien Stormacq (guest): And these deployments and observability monitoring will always be very specific to the platform where you're deploying it. So that part, it's something that you would need to rewrite anyway.
[00:18:57] Leo Dion (host): Yeah. And obvious thing is if you're gonna use something specific to Amazon, like Dynamo or S3. That's where, I mean, that's kind of more where it is than it is the Lambda.
[00:19:08] Sébastien Stormacq (guest): S3 is pretty straightforward these day because many other cloud provider have an history, like something which has roughly the same API as S3. So S3 code can be a bit portable. Right now, of course, if you go to Dynamo and it's 100% specific to Amazon, there.
[00:19:27] Leo Dion (host): Dynamo is the key value one, right?
[00:19:30] Sébastien Stormacq (guest): It's a key value NoSQL database, entirely managed serverless. Nothing to install. You. Just make your H-G-T-P-A-P-I request to put or get your data.
[00:19:39] Leo Dion (host): And Aurora is the MySQL clone, right?
[00:19:42] Sébastien Stormacq (guest): All Aurora postgres or MySQL compatible database, but really design for the cloud. So the storage layer of Postgres or MySQL has been redesigned to take advantage of multiple data center and a high level of replication inside the data center. So every time you write data on Aurora, it's replicated to six different place in at least three different data center.
[00:20:03] Sébastien Stormacq (guest): But the front end, the things that accept the SQL is compatible with Postgres on MySQL. So from your application point of view. It doesn't change a scene, you just send the same sequel. But the storage engine behind the scene is totally new and developed for the cloud.
[00:20:19] Leo Dion (host): Okay. So, did you, were you able to attend Mikayla's talk at Server Side Swift?
[00:20:26] Sébastien Stormacq (guest): Yes, and that was an eye opener for me. Maybe you can explain the context there. Oh, I. can do it. It's.
[00:20:30] Leo Dion (host): Okay, so, I'll post a link and maybe a card here on YouTube, but basically McKayla if you don't know McKayla, you probably aren't a developer in Swift. So, McKayla had a really great talk at the server site Swift conference about, was it uploading a photo, right?
[00:20:48] Sébastien Stormacq (guest): Yeah, I think the
[00:20:49] Leo Dion (host): you upload a photo through
[00:20:50] Sébastien Stormacq (guest): do you upload a photo to, to the cloud? It cannot be that difficult. Can.
[00:20:55] Leo Dion (host): And what was great about it wasn't a tutorial on how to do it, it was a how do I put it? Empathy, I guess would be the right word. Or maybe an example of like frustration learning how to do something in server side swift that you would think is fairly simple but is a rabbit hole
[00:21:17] Understanding AWS Security and Authorization
---
[00:21:17] Sébastien Stormacq (guest): Actually, I don't think the challenge was because it was swift on the server side. The challenge was first understand the security, the authorization system from AWS, and she was using Heroku to deploy, which give you access to. Part of the underlying AWS resource, but not totally. So that was one, one of
[00:21:38] Leo Dion (host): Well, but even like, how do you upload a file in the server side switch? Like even that part like, yeah, the. AWS Lambdahe Google result was basically use S3 and then from there Yeah. That would you I'm coming to a question obviously, but like, one of, one of the things that. People commonly will say with any Amazon service is the secure, like the security, it's great, but it's also, it's so good that it's difficult to get started.
[00:22:05] Leo Dion (host): And you know, you're gonna find that with aw, with Lambda because you have to set up security roles and IAM stuff. What pointers or what, like what guidance do you have on that as far as like. Oh man, my ado, my Lambda won't call my SQL server because this role isn't like how should people figure that stuff out or get started?
[00:22:26] Sébastien Stormacq (guest): To get. With Swift and Lambda I'm currently writing a lot of documentation. So if you go to the Swift a s Lambda Runtime Project, the read me page as a lot of example and I try to give very practical and details about you have to do that, you have to do that with the exact comment before, assuming that people know much about the cloud.
[00:22:48] Sébastien Stormacq (guest): So it is really written with an eye of someone that knows Swift. That would like to deploy on the cloud, but doesn't is not an expert on AWS I'm not writing that for AWS customer. I'm writing that for Swift developers to bring them to, to AWS. The only big prerequisite, and I cannot avoid that, is to have an AWS account and have an access key, secret key, which is equivalent of a use on password at API level to interact with AWS.
[00:23:13] Sébastien Stormacq (guest): And I'm not re rewriting the doc for that. I'm linking to existing doc on, on AWS, but once that is, that prerequisite is met I'm trying to really list all the steps so it's not finished, it's work in progress. If you go to the Read Me today in December, 2024, if you're listening this shortly after publication.
[00:23:32] Sébastien Stormacq (guest): You will see still a couple of to-dos or sections that are missing, but the goal is in the next couple of months to have a fairly complete a set of documentation including for deployment with different options of deploying in the console, deploying through the command line, deploying with infrastructure as code tool like Sam, or maybe five time, tools not from AWS like Terraform, pmi other infrastructure code tools. So I.
[00:23:57] Sébastien Stormacq (guest): try to be quite. Complete there, including in the code sample. So you mentioned talking to a database. It's a very common use case, so there will be, it's not there yet. An example of a Lambda function that talks to a postgre.
[00:24:11] Sébastien Stormacq (guest): There is an example that talks to a three, that talks to dynamo db. So you can find all these example, and these examples are super short, like 10 lines of code maximum to show you how to get the basic bricks in motion or in place.
[00:24:25] Leo Dion (host): What do you like? What do you think is most of the confusion? When setting up security roles and things like that, like where do you think, where do you think it comes from? Like what is the mental model that Amazon has that the average developer doesn't have that is making the thing, making it so challenging.
[00:24:45] Leo Dion (host): You know what I mean?
[00:24:46] Sébastien Stormacq (guest): There are different ways to do things as I said in the console, in the command line. And things evolve over time as well. We try to simplify over time. So if you Google for solution like Mickayla did she found tons of old blog posts or results that are not accurate anymore, and.
[00:25:04] Leo Dion (host): I am just thinking like, don't use AI than to ask, because those models are probably trained on old blog
[00:25:10] Sébastien Stormacq (guest): All data
[00:25:11] Leo Dion (host): That's even worse. Yeah.
[00:25:13] Sébastien Stormacq (guest): that's, that, that's true. So one challenge is the profusion of documentation. There is too many documentation including on our website. I'm not just talking about third party blocks in including on AWS and sometimes it's outdated documentation as well.
[00:25:27] Sébastien Stormacq (guest): The second thing, I think, I if you start to use the cloud, any cloud, Google, Microsoft, AWS, just to mention these three, spend half a day, one day learning the basic of security. It'll save you time for the rest of your life. If you, once you understand the security model on AWS, what is an access easy credit key can.
[00:25:46] Sébastien Stormacq (guest): Or can I get one? Either it's a permanent one assigned to my user or a temporary one that I receive through a role that I, and I assume a role. Once you understand that basic, it's not that complicated, but most of the developers that I know, you know, we don't read the doc, we don't need to read the dogs.
[00:26:01] Sébastien Stormacq (guest): So we go straight to the code and then we hit the, this type of programs. So my advice would be spend. Little time. Honestly, it's not that complicated, at least the foundation, the basic to understand what we are talking about. It'll save you time a lot and read the error message. The error message are incredibly descriptive, and just by reading the error message most of the time we can point to the source of the challenge as well of the problem.
[00:26:26] Leo Dion (host): When you said about documentation, well, luckily Apple doesn't have that problem, right. Of having old documentation on their wink. Um, yeah. Do you, besides your what, your your readme that you're talking about, any other links that you would recommend that would be the latest and have, like, this is what you should read to really deep dive into how it's supposed to work.
[00:26:48] Sébastien Stormacq (guest): For Swift on Lambda? Specifically for Lambda in general,
[00:26:51] Leo Dion (host): just how the whole security system works.
[00:26:54] Sébastien Stormacq (guest): I can share a couple of links with you. You can put that in the notes of the podcast. But yes, the getting started usually in all aw s doc per service, there is a getting started page that explain the main concept in a very clear way.
[00:27:08] Sébastien Stormacq (guest): That's usually a very good starting point. PE as I said, we developer and I include myself in that bunch of people. We don't spend time reading the doc and sometimes we should a.
[00:27:19] Leo Dion (host): Right, right. Like yeah, there's missing pieces when you just try to get it done right. And if you read the doc, it will fill in a lot of blanks and then you don't have to like keep Googling every or atch a PT every error message that you get. So yeah, totally agree a hundred percent.
[00:27:36] Developing and Deploying Swift on AWS Lambda
---
[00:27:36] Leo Dion (host): Let's talk about deployment. So I assume this is a Swift package, right? You can develop it on Xcode. Is there a dev container now I.
[00:27:48] Sébastien Stormacq (guest): There is no dev container provided by us. It's easy to create one, but yes, it's a swift package you include in your package. That swift class dependency on the runtime.
[00:27:57] Leo Dion (host): I've started developing a visual studio code for especially when I need to see if something will work in a a, so I was wondering if we have that capability with Lambda. Oh, awesome. Okay.
[00:28:08] Sébastien Stormacq (guest): I'm doing most of my development in Visual Studio.
[00:28:11] Leo Dion (host): See, it's like a real.
[00:28:13] Sébastien Stormacq (guest): time to time with Xcode just to see if it still works and know the package that Swift, the SPM support in Xcode is decent. So it works quite well with Xcode as well. I tend to observe that the code completion is a bit better in Xcode and in Visual Studio Code.
[00:28:26] Sébastien Stormacq (guest): But we have copilot, which helps a lot as well. Now both in Xcode and in Visual Studio Code. So you import that package, you create your main, executable, a swift function, Lambda function. It's an executable. You implement an interface called Runtime that has one function that receive two parameters.
[00:28:42] Sébastien Stormacq (guest): The event. So the J that you receive from whatever is calling you the API gateway, for example. And the other one is the Lambda context. So it's a bit of information about where you are running, how much memory is available, for example, what Is the request ID and some other information about the context.
[00:28:58] Sébastien Stormacq (guest): And then you do whatever business you need to do. And your return a response, typically a JSON response. And that's pretty much it. The neuro run time integrates with the swift server lifecycle. So if you have a database driver that needs to start and to be shut down correctly to manage the TCP connection and the concurrency, it fits nicely into that.
[00:29:16] Sébastien Stormacq (guest): You can write lambda function that stream their response over time. That's also something new with the new V two runtime. So instead of responding a big JSON in one shot, you just stream your bites as you receive them or
[00:29:29] Leo Dion (host): it Jason Lines? There's like a, there's a few of them I've noticed in Hummingbird that supports Jason Lines and Jason
[00:29:36] Sébastien Stormacq (guest): I guess it is. I didn't look at that part in a ING bird yet, but I think A ING Bird two also support a streaming of response. That's
[00:29:43] Leo Dion (host): Okay.
[00:29:44] Sébastien Stormacq (guest): That's convenient. If you have a long computation or big documents that you cannot return in one shot, you can stream them as you receive or as you generate them.
[00:29:52] Sébastien Stormacq (guest): You can also run. Background tasks. So there is a short moment of time in between the lamb. The moment the lambda function returns response to the client, and the moment the container the micro VM is shut down. There is a you can run code there. Of course, you're going to be charged for that CPU cycle.
[00:30:09] Sébastien Stormacq (guest): But you can do cleanup. Task like, pushing logs, for example, closing DCP connection. So the idea is to respond to the client as fast as you can, so the client get this answer and then you do your cleanup task after. That's also a pattern, which is supported by the new run time, and we've got samples and documentation for all of that, but at the end,
[00:30:29] Leo Dion (host): sorry, go ahead. Go ahead.
[00:30:30] Sébastien Stormacq (guest): Now at the end, you need to compile your code. Most of us, we are developing Swift Lambda on Mac on a RM, but Lambda doesn't run on mac a m, so we need to cross compile for Amazon Linux. Today we are doing that with Docker. So there is a swift plugin integrated with the runtime. You can just type swift.
[00:30:47] Sébastien Stormacq (guest): Package archive and it will trigger the entire sequence to get a container running compile inside the container to compile, to create a binary compatible for Amazon Linux, which is the operating system running on a Lambda, and at the end it will produce a zip file. And then it's your responsibility to deploy that zip file.
[00:31:06] Sébastien Stormacq (guest): And there again, you have multiple options. You can go graphically in the AWS Lambda console click upload my zip file. It works. It's ideal to learn and to understand how it works. It's not good for production. Anything that you do manually. It's not good for production. it's. better to automate and write scripts.
[00:31:24] Leo Dion (host): Yeah, I was gonna ask, is there like, any good like GitHub actions to do this?
[00:31:29] Sébastien Stormacq (guest): To deploy on Lambda? I never try. Because there is a GitHub, Like, GitHub actions like system in AWS, it's called Code Build. It's a pipeline for ci. Most of our customer are describing the infrastructure they want, you know, text file. Like in a Yammer or JSON file, you say, Hey, I want an API gateway.
[00:31:46] Sébastien Stormacq (guest): I want that lambda function with that zip. I want the API gateway to call the lambda function. I need a policy because the Lambda function will call DynamoDB, blah, blah, blah. So you describe that in a Yammer file, and you give that to a tool that will create infrastructure for you automatically in the cloud.
[00:32:01] Sébastien Stormacq (guest): And the typical way to do that for Lambda function and serverless application on AWS, it's called sam which means serverless. Application model. SAM
[00:32:11] Leo Dion (host): Okay. Model. Yeah.
[00:32:12] Sébastien Stormacq (guest): That's the end to end workflow where you deploy at the end, the function is deployed. And then you can use Ker or any HTTP client rest API client tool to invoke your function.
[00:32:22] Sébastien Stormacq (guest): You can also test locally.
[00:32:24] Leo Dion (host): I was gonna ask
[00:32:24] Sébastien Stormacq (guest): just swift run. And it'll detect, oh, I'm on the Mac. I'm not inside the Lambda container. So it will start a mini HTTP server and you can just curl to a local host or 127 0 0 1 on port 7,000 and pass your JS on file there,
[00:32:42] Testing and Integration with AWS Services
---
[00:32:42] Leo Dion (host): Is there any testing? Testing libraries?
[00:32:45] Sébastien Stormacq (guest): For Lambda?
[00:32:46] Leo Dion (host): Do you hear the
[00:32:47] Sébastien Stormacq (guest): Not that I know. No. So you I typically do the unit test with swift testing or existing test before, like we do. Usually I do some integration testing, like starting the mini server, sending
[00:33:00] Leo Dion (host): Let me ask that question again, just
[00:33:01] Leo Dion (host): So can you do any stuff with like swift testing or XE testing?
[00:33:05] Sébastien Stormacq (guest): Locally on your local machine? Yes. And actually it's a best practice. Your Lambda code is just the entry point and the exit point. All in between the two is your business logic and you should write. Test, don't you? For all of that. And yes, you can run locally your SWIFT test and XCCT test. What I Do also, it's integration tests.
[00:33:25] Sébastien Stormacq (guest): So I, I run the server locally with Swift Run. I send a couple of json payload and verify the JSON response that are coming out. So it's a bit more than unit test. It's like testing the entire function in one shot and. Some customer are also deploying and that's one of the advantage of the clouds.
[00:33:43] Sébastien Stormacq (guest): All the clouds, not only AWS, is that once you have a script to deploy into production, you can run the same script to deploy into another environment. And so you have the exact same infrastructure in dev test, the staging production, so you can create temporary environment for your test.
[00:34:01] Leo Dion (host): Could you, like, let's say you're using services Postgres. Key manager, S3 dynamo. Is there a way to test that locally if you're integrating with those services? Or what would you recommend outside of like mocking those services, I guess and architecting it with like, you know, that
[00:34:22] Sébastien Stormacq (guest): Yes, there is an open source project called Local Stack, which is quite impressive. They try to mock the majority of the A-W-S-A-P-I, so it start a server. It's a mock for DynamoDB for three, for the Q-S-Q-S-S-N-S, the mail system typically it runs inside the container. And you can write script, testing, script as complex as you want.
[00:34:41] Sébastien Stormacq (guest): That will. Create the local stack you point your environment to local stack, and then you can develop locally. You don't need to have even an internet connection to, to develop against the A-W-S-A-P-I.
[00:34:53] Leo Dion (host): Yeah. Yeah. Yeah. That's awesome. Just a few more questions before we close out. Is the AWS Lambda stuff, is it all Swift six now and,
[00:35:03] Sébastien Stormacq (guest): Yes. So we are working since two, three months on that. So there is a new version of the runtime. If you go to GitHub, swift, AWS. Lambda runtime. Right now, the main branch, it's not tagged yet, it's not V two, but the main branch contains code that has all these API that I mentioned, background tasks, the streaming, and it's fully swift six compliance.
[00:35:24] Sébastien Stormacq (guest): We compiles with all errors. We, without warning, we fully embrace I think a weight and underneath we're still using swift, Neo to make HTT P request to the Lambda API.
[00:35:34] Leo Dion (host): Awesome. What. What new tech are you as far as for developers? Are you excited about? That's either come out in the last few months or coming out soon?
[00:35:47] Sébastien Stormacq (guest): I start to be excited and it's not going to be super original. I'm sorry about the coding assistant, the gen AI coding assistant. I was trying copilot inside X code the other day. It saved me hours of typing boring code to validate command line arguments. Kind of guess what I'm going to write. I just typed the first two letters and I.
[00:36:05] Sébastien Stormacq (guest): have three, four lines that I can accept with just one, one keystroke.
[00:36:09] Sébastien Stormacq (guest): So that, that's super useful. On Amazon, we have something equivalent called Amazon Queue for Developer Running Inside Visual Studio Code. And that one, it's not trained on Swift officially, it does not support Swift, but it can help a bit. But I use it more like a. Chat, like, Hey a Shell script, something that would take me 15 or 20 minutes to write, I know how to do
[00:36:29] Leo Dion (host): scripts are amazing as far as gen generating code. I've sent this before on the show, but like,
[00:36:35] Sébastien Stormacq (guest): regular
[00:36:36] Leo Dion (host): They're the gold. Like, oh, regular exp. Yeah. Anything that, like we've said, anything that's been out for like 30 or 40 years, it's gonna have the model data for it. If you're asking about some like UI thing that has only been out for like three months, you're gonna get, you're gonna get screwed.
[00:36:52] Leo Dion (host): Yeah.
[00:36:53] Sébastien Stormacq (guest): But one year ago I would've a different answer saying, okay, these assistance, yeah, it's a gadget. It's not super useful. But honestly, all the work that has been done in the last year, we are at a stage now where a developer cannot ignore these tools anymore. It's like cutting with all Stack overflow or we, without Google, you don't do that anymore
[00:37:10] Leo Dion (host): That's a good way to think about it. Yeah. And it's not replacing chops, it's just
[00:37:14] Sébastien Stormacq (guest): No,
[00:37:15] Leo Dion (host): no, it's just assisting and like, and answering questions.
[00:37:18] Leo Dion (host): You know, like whether you, what is it? You should put concrete and pizza and stuff like that. But yeah. Yeah. Very cool. Anything else you wanna plug before we close out?
[00:37:27] Sébastien Stormacq (guest): Try the Swift Lambda Run Times. If you are a Swift developer, if you have a need to run code on a server go to Swift swift server on, on GitHub and read the, read me. Give us feedback, please. If something is unclear, especially as a, as someone new to AWS don't, there is no stupid question.
[00:37:45] Sébastien Stormacq (guest): The only stupid question is the one you are not going to ask. So open an issue. I'm reading the issue. Join us on the swift server Slack, ask question. There is a, Lambda channel there. I'm spending most of my day keeping an eye on that channel as well. There is the swift server forums as well.
[00:38:01] Leo Dion (host): I
[00:38:01] Sébastien Stormacq (guest): So ask question, give us
[00:38:03] Leo Dion (host): thought of a question for you actually before we close out. Why would you're doing such a good job selling AWS Lambda, why would you ever go with another Amazon service like EC2 or Amplify or something else?
[00:38:16] Sébastien Stormacq (guest): For my need as a developer, I want. Zero. I will not do it. I will go serverless, I will go with Lambda. The only reason if ever I have that use case as I said in the beginning, depending on the invocation patterns, if you have workloads that are running for long period of time and the constant CPU
[00:38:35] Leo Dion (host): gotta find that sweet spot.
[00:38:36] Sébastien Stormacq (guest): The pricing might be, higher on Lambda and than a traditional solution, but beside that I will not do it. Why our customer are still choosing containers or vm. One reason is history, and they have like 40 years of IT history. They are used to manage virtual machines, but not containers and about containers.
[00:38:54] Sébastien Stormacq (guest): For some long, if you need to run a server, for example, you didn't fully embrace the serverless patterns of the cloud, maybe it's like a sweet spot in between virtual machines and full serverless where you feel you still understand a bit or manage the infrastructure.
[00:39:09] Leo Dion (host): where you need to have more regulation and it's like, oh yeah, you can't do this on a Lambda. It needs to be this machine with this. Yeah.
[00:39:16] Sébastien Stormacq (guest): that might be a reason. Some customers think that if they deploy to customer they will have a bit more portability in case they want to change cloud provider, which is partially true. So that's another reason why some customer are using virtual machines or docker containers. I.
[00:39:32] Leo Dion (host): Thank you. Sebastian, where can people find you online?
[00:39:36] Sébastien Stormacq (guest): Everywhere on Blue Sky, it's LinkedIn Threads, mastodons I'll put my links in. I'll send you my links and you can put that in the comments. Yeah.
[00:39:46] Leo Dion (host): Yeah. Well, thank you so much for coming on Sebastian. We'll link to your presentation as well. It was great to finally have you on and chat. People can find me on X at Leo GD on Mastodon at Leo g dn. C, IM LinkedIn, yada. If you're watching this on YouTube, please like and subscribe.
[00:40:04] Leo Dion (host): And if you're listening to this on a pod podcast player, please post a review. Thank you so much for joining me for today's episode. Consider joining our Patreon if you want early access, and we will see you again. Bye everybody.
[00:40:21] Sébastien Stormacq (guest): Bye.