Continuous Deployment in AWS Lambda
-
Upload
shu-ting-tseng -
Category
Software
-
view
420 -
download
1
Transcript of Continuous Deployment in AWS Lambda
Who am Iclass SoftwareEngineer(Human):
def __init__(self):self.interests = [
"AWS"]
self.languages = ["Python","Golang"
]
–AWS
AWS Lambda is a zero-administration compute platform for back-end web developers that runs
your code for you in the AWS cloud and provides you with a fine-grained pricing structure.
–AWS
AWS Lambda runs your back-end code on its own AWS compute fleet of Amazon Elastic Compute Cloud (Amazon EC2) instances across multiple
Availability Zones in a region, which provides the high availability, security, performance, and
scalability of the AWS infrastructure.
Cloud Computing in AWS• Elastic Compute Cloud (EC2)
• Infrastructure as a Service
• Abstract hardware
Cloud Computing in AWS• Elastic Compute Cloud (EC2)
• EC2 Container Service (ECS)
• Container as a Service
• Abstract OS
Cloud Computing in AWS• Elastic Compute Cloud (EC2)
• EC2 Container Service (ECS)
• AWS Lambda
• Function as a Service
• Serverless
S3 event
1 def lambda_handler(event, context):2 s3 = boto3.client('s3')3 4 bucket = event['Records'][0]['s3']['bucket']['name']5 key = event['Records'][0]['s3']['object']['key']6 print "S3 Bucket: %s" % bucket7 print "S3 Key: %s" % key8 ……
Version and Alias• Version
• 1, 2, 3, 4 ….
• Incremental integer
• Immutable
• Alias
• feature -> 4
• testing -> 8
• Mutable
Problem• So you wanna deploy…
• Upload a zip to S3
• Create or update function
• Configure version
• Create or update alias
• And you may have 100+ functions
Behind the scene - 2packages/
my-func-1/
bfb53884976e70966a9e8a8d5133bcb2e1c06691/
eed8ccf9ea22099cef07b0a2012085cd45e1d3ad/
……
Behind the scene - 3packages/
my-func-1/
bfb53884976e70966a9e8a8d5133bcb2e1c06691/
lambda.zip
function.json
function.json{
"runtime":"python2.7",
"handler":"main.lambda_handler",
"timeout":300,
"memory":128
}
Behind the scene - 4packages/
my-func-1/
bfb53884976e70966a9e8a8d5133bcb2e1c06691/
eed8ccf9ea22099cef07b0a2012085cd45e1d3ad/
testing
……
deployer.py
class Deployer(object):
def __init__(self): self.s3_client = boto3.client("s3") self.lambda_client = boto3.client("lambda") self.slack = Slacker(open("config/slack-token").read()) self.slack_channel = json.load(open("config/slack.json"))
deployer.py
1 class Deployer(object):2 3 def deploy(self, record):4 bucket = record["s3"]["bucket"]["name"]5 key = record["s3"]["object"]["key"]6 7 lambda_function = LambdaFunction(bucket, key)8 version = self.put_function(lambda_function)9 self.put_alias(lambda_function, version)
main.py
1 import boto3, json2 from deployer import Deployer3 4 def run(event, context):5 d = Deployer()6 print "boto3 version:", boto3.__version__7 print json.dumps(event, indent=2)8 for record in event["Records"]:9 d.deploy(record)
Pros
• Serverless (yes we are lazy…)
• One deployer manages
• many functions
• many stages (using alias)
• Perfectly fits in our workflow
In KKStream
• From 2016/02/01 to 2016/05/31
• 12 developers
• 99 functions
• 4288 deployments
• 1 fork
Future work
• Add event source mapping
• More configurations
• https://github.com/KKStream/aws-lambda-deployer