Async is one of the most requested feature and it’s finally in swift. This simplifies the workflow greatly

let url = URL(string: "htts://api.github.com/users/hadley/orgs")!
let (data, _) = try await URLSession.shared.data(from: url)

Really its that easy

note that you will need to use this function in an async context only.

func getId() async->Int? {
do {
let url:URL = URL(string: "https://api.github.com/users/hadley/orgs")!
let (data, _) = try await URLSession.shared.data(from: url)
let res:SampleJson = try JSONDecoder().decode([SampleJson].self, from: data)[0]
return res.id
} catch {
debugPrint("\(error)")
return nil
}
}
import SwiftUI
struct ContentView: View {
@State var id_:Int = 0…


String api key SECURELY is a big headache for many, but not to worry, AWS has a great service for that

This is a really simple yet safe solution to the permission problem

  1. go to secrets manager console
  1. click store a new secret


Cloudfront is a great content distribution network which speeds up your websites/ api significantly, however one of the hurdle is you need to invalidate cache when your endpoint is updated

Setting up IAM permission

This is pretty easy

  1. set up your policy

Go to IAM console, and select policies

2. Create policy, select json and put this in

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "cloudfront:CreateInvalidation",
"Resource": "arn:aws:cloudfront::<accountId>:distribution/<distributionId>"
}
]
}


If you have been using AWS Lambda, one of the nicest feature is that you can check, test and edit code directly from console. However, this is limited to 3 MB of package size, once you install pretty much any packages, it will exceed that quota.

AWS Lambda layer is used instead of installing many libraries for use in AWS Lambda functions. This gives you 250 MB headroom to install libraries.

This is easier that you think,

requirements:

docker, bash

  1. create a requirement file
lambdaLayer
|- requirements.txt

2. download the build script

for convenience, I have published the build script…


What is a stack?

A stack is a collection of serverless functions, services, and database which are defined within a cloudformation stack in accordance to the cloudformation docs.

A serverless stack in the definition of villa market is where a stack does not contain any service that needs to be managed manually eg EC2, virtual machine, or Kubernetes-like services.

a secure serverless stacks should have the following features

  1. permission should be defined within the template.yml file
  2. there should be no hard coded passwords/secret key in the stacks
  3. every function/services should have resource-based-permission set up within the template
  4. the stacks should not contain hard-coded resource…

Nic Wanavit

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store