SlideShare a Scribd company logo
Build Process:
Fast Deployments To
Multiple Lambda Functions
Problem Description
• Multiple Microservices
• Each service has ~50 lambda functions
• Each function handling very specific task
• Build process uses CircleCI, running within containers
• Golang binary to be compiled for each function
– Golang uses all available CPU in build environment
– Compiling in parallel within build environment slows things down
– Build and test was taking ~25 minutes per app
2
Potential Solutions
• CircleCI caching
– Caching multiple binaries etc. takes up a lot of space
– More than 5 minutes devoted to save and restore cache
– Does not lower compile times sufficiently
• Parallel compilation
– Each “go build” appears to use all available CPU
– Parallel compile times actually appear slower than sequential
• Build using a build lambda
– Each build runs within an independent environment
– Horizontal scaling is automatic
– Helps to separate concerns during the build process
– DRY build code that can be re-used across all our apps
3
Inside the lambda environment
• Based on container technology
• Runs Amazon Linux
• CPU resources tied to configured memory size
• Maximum execution time of 5 minutes
– AWS might be increasing this limit in the future – talk to Support
• Only writable area is /tmp
– Ephemeral
• Files written to /tmp are persistent if the invocation uses an
existing “warm” container
– Limited to 512 MB
• AWS might be increasing this limit in the future – talk to Support
• Lambda handler runs as root user
4
Setting up the lambda env for builds
• Set GOPATH and GOROOT to live within /tmp
• Check if Golang is installed, install if required
– It will not be installed in a “cold” lambda container
– If not installed, download and install within /tmp/go
• Check if Apex is required, install if not already done
– We use Apex for older apps developed before native AWS Go
support, using a NodeJS shim around the Golang binary
– Apex is installed only if specified in the lambda’s event JSON
• Checkout application code
– Uses a Github “machine user” token set as an env variable
– Checks out into /tmp
5
Testing
• We use “go test” to run unit tests
• Coveralls.io for test/coverage reporting
• Test output is returned as part of the lambda’s response
JSON
– Output is base64-encoded
– CircleCI build script collates outputs from all build-lambda
invocations within a build, then uploads them to Coveralls
• If a test fails, lambda invocation fails
– This failure is detected by the CircleCI build scripts, which take
appropriate actions
6
Building
• We use “go build” to build the binary
• Code dependencies are vendored and stored in the
repository
• Built binary is uploaded to an S3 bucket specified in the
event JSON, using the Python AWS SDK
7
Invoking the build lambda from the CI
• Depend on convention to separate function code and shared
code
• Iterate through all directories containing code:
– Invoke build-lambda in test-only mode for shared code
– Invoke build-lambda in test+build mode for function code
• Use GNU Parallel to invoke build-lambda simultaneously
– Build AWS CLI commands for each invocation, save to file
– Pipe saved file through GNU Parallel to run commands in parallel
– Halt build if any build-lambda invocation fails
• Use JQ to parse lambda’s invocation result from AWS, and
take appropriate actions:
– Build error if .FunctionError is not null
– Base64-decode test coverage output and append to Coveralls
– Output .LogResult to STDOUT if .FunctionError is not null
8
Logging
• The build-lambda logs to Cloudwatch
• The CircleCI script invokes the build-lambda using the
“--log-type Tail” AWS CLI option
– This returns a field in the result named ”.LogResult”
– Contains the last 4K of logs, base64-encoded
• If the invocation failed, then the CircleCI script outputs
the base64-decoded contents of “.LogResult” to
STDOUT
• Build errors can be easily viewed on the CircleCI build
output view
• Further log processing can be done using Cloudwatch
9
Deploying built binaries to functions
• Use AWS CLI’s “update-function-code” command
• Directly deploy from S3 without need for file transfers
• Integration tests performed by downloading binaries from
S3 into the CircleCI environment, and running tests
against them
– This ensures that the actual binary that was tested is deployed to
the lambda function
10
Q & A
Q & A
11

More Related Content

PDF
PDF
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
PDF
Developing Microservices with Apache Camel, by Claus Ibsen
PDF
MuleSoft Manchester Meetup #3 slides 31st March 2020
PDF
Efficient Parallel Testing with Docker
PDF
AWS Lambda Function with Kotlin
PDF
Meetup Melbourne August 2017 - Agile Integration with Apache Camel microservi...
PPTX
Manchester MuleSoft Meetup #6 - Runtime Fabric with Mulesoft
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
Developing Microservices with Apache Camel, by Claus Ibsen
MuleSoft Manchester Meetup #3 slides 31st March 2020
Efficient Parallel Testing with Docker
AWS Lambda Function with Kotlin
Meetup Melbourne August 2017 - Agile Integration with Apache Camel microservi...
Manchester MuleSoft Meetup #6 - Runtime Fabric with Mulesoft

What's hot (20)

PPTX
Next generation pipelines
PDF
Open stack ocata summit enabling aws lambda-like functionality with openstac...
PPTX
PPTX
Going serverless with aws
KEY
Make It Cooler: Using Decentralized Version Control
PDF
The Three Musketeers
PPTX
Arch9 - A cloud based continuous delivery implementation
PPTX
2020.02.15 DelEx - CI/CD in AWS Cloud
PPTX
Automated testing on steroids – Trick for managing test data using Docker sna...
PDF
The future of paas is serverless
PDF
Kafka on Kubernetes: Keeping It Simple (Nikki Thean, Etsy) Kafka Summit SF 2019
PPTX
How to deploy your Apps in serverless-way using App Engine.pptx
PPTX
Better Kafka Performance Without Changing Any Code | Simon Ritter, Azul
PPTX
Building flexible ETL pipelines with Apache Camel on Quarkus
PDF
What's new with Apache Camel 3? | DevNation Tech Talk
PDF
Immutable Infrastructure: Rise of the Machine Images
PPTX
Chatbots with Serverless
PDF
Kong API
PPTX
Encrypting Kafka messages at rest to secure applications | Robert Barnes, Has...
PPTX
Serverless
Next generation pipelines
Open stack ocata summit enabling aws lambda-like functionality with openstac...
Going serverless with aws
Make It Cooler: Using Decentralized Version Control
The Three Musketeers
Arch9 - A cloud based continuous delivery implementation
2020.02.15 DelEx - CI/CD in AWS Cloud
Automated testing on steroids – Trick for managing test data using Docker sna...
The future of paas is serverless
Kafka on Kubernetes: Keeping It Simple (Nikki Thean, Etsy) Kafka Summit SF 2019
How to deploy your Apps in serverless-way using App Engine.pptx
Better Kafka Performance Without Changing Any Code | Simon Ritter, Azul
Building flexible ETL pipelines with Apache Camel on Quarkus
What's new with Apache Camel 3? | DevNation Tech Talk
Immutable Infrastructure: Rise of the Machine Images
Chatbots with Serverless
Kong API
Encrypting Kafka messages at rest to secure applications | Robert Barnes, Has...
Serverless
Ad

Similar to Fast Deployments to Multiple Golang Lambda Functions (20)

PPTX
Introduction to AWS Amplify and the Amplify CLI Toolchain
PDF
Continuous Delivery: 5 years later (Incontro DevOps 2018)
PDF
Serverless in production, an experience report
PDF
Build reactive systems on lambda
PDF
Serverless in production, an experience report (CoDe-Conf)
PDF
DevOps with Serverless
PPTX
Apigee deploy grunt plugin.1.0
PPTX
End-to-end CI/CD deployments of containerized applications using AWS services
PDF
Serverless in production, an experience report (FullStack 2018)
PDF
AWS Lambda from the trenches
PDF
Serverless in Production, an experience report (AWS UG South Wales)
PDF
Serverless in production, an experience report (Going Serverless)
PDF
AWS Lambda Presentation (Tech Talk DC)
PPTX
How to improve CI CD for any Node.js application
PPTX
Lessons learned after a year of lambda - AWS Community Day SF 2017
PDF
Serverless in production, an experience report (JeffConf)
PDF
AWS Lambda
PDF
Play Framework + Docker + CircleCI + AWS + EC2 Container Service
PPTX
Docker for Development
PDF
DevOps Spain 2019. Pedro Mendoza-AWS
Introduction to AWS Amplify and the Amplify CLI Toolchain
Continuous Delivery: 5 years later (Incontro DevOps 2018)
Serverless in production, an experience report
Build reactive systems on lambda
Serverless in production, an experience report (CoDe-Conf)
DevOps with Serverless
Apigee deploy grunt plugin.1.0
End-to-end CI/CD deployments of containerized applications using AWS services
Serverless in production, an experience report (FullStack 2018)
AWS Lambda from the trenches
Serverless in Production, an experience report (AWS UG South Wales)
Serverless in production, an experience report (Going Serverless)
AWS Lambda Presentation (Tech Talk DC)
How to improve CI CD for any Node.js application
Lessons learned after a year of lambda - AWS Community Day SF 2017
Serverless in production, an experience report (JeffConf)
AWS Lambda
Play Framework + Docker + CircleCI + AWS + EC2 Container Service
Docker for Development
DevOps Spain 2019. Pedro Mendoza-AWS
Ad

Recently uploaded (20)

PPTX
OOP with Java - Java Introduction (Basics)
DOCX
573137875-Attendance-Management-System-original
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
PPT
Chapter 6 Design in software Engineeing.ppt
PPTX
Practice Questions on recent development part 1.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
AgentX UiPath Community Webinar series - Delhi
PPTX
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Internship_Presentation_Final engineering.pptx
PDF
Queuing formulas to evaluate throughputs and servers
PDF
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPT
Drone Technology Electronics components_1
OOP with Java - Java Introduction (Basics)
573137875-Attendance-Management-System-original
Embodied AI: Ushering in the Next Era of Intelligent Systems
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
Chapter 6 Design in software Engineeing.ppt
Practice Questions on recent development part 1.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
AgentX UiPath Community Webinar series - Delhi
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
Structs to JSON How Go Powers REST APIs.pdf
Strings in CPP - Strings in C++ are sequences of characters used to store and...
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Internship_Presentation_Final engineering.pptx
Queuing formulas to evaluate throughputs and servers
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
Arduino robotics embedded978-1-4302-3184-4.pdf
Drone Technology Electronics components_1

Fast Deployments to Multiple Golang Lambda Functions

  • 1. Build Process: Fast Deployments To Multiple Lambda Functions
  • 2. Problem Description • Multiple Microservices • Each service has ~50 lambda functions • Each function handling very specific task • Build process uses CircleCI, running within containers • Golang binary to be compiled for each function – Golang uses all available CPU in build environment – Compiling in parallel within build environment slows things down – Build and test was taking ~25 minutes per app 2
  • 3. Potential Solutions • CircleCI caching – Caching multiple binaries etc. takes up a lot of space – More than 5 minutes devoted to save and restore cache – Does not lower compile times sufficiently • Parallel compilation – Each “go build” appears to use all available CPU – Parallel compile times actually appear slower than sequential • Build using a build lambda – Each build runs within an independent environment – Horizontal scaling is automatic – Helps to separate concerns during the build process – DRY build code that can be re-used across all our apps 3
  • 4. Inside the lambda environment • Based on container technology • Runs Amazon Linux • CPU resources tied to configured memory size • Maximum execution time of 5 minutes – AWS might be increasing this limit in the future – talk to Support • Only writable area is /tmp – Ephemeral • Files written to /tmp are persistent if the invocation uses an existing “warm” container – Limited to 512 MB • AWS might be increasing this limit in the future – talk to Support • Lambda handler runs as root user 4
  • 5. Setting up the lambda env for builds • Set GOPATH and GOROOT to live within /tmp • Check if Golang is installed, install if required – It will not be installed in a “cold” lambda container – If not installed, download and install within /tmp/go • Check if Apex is required, install if not already done – We use Apex for older apps developed before native AWS Go support, using a NodeJS shim around the Golang binary – Apex is installed only if specified in the lambda’s event JSON • Checkout application code – Uses a Github “machine user” token set as an env variable – Checks out into /tmp 5
  • 6. Testing • We use “go test” to run unit tests • Coveralls.io for test/coverage reporting • Test output is returned as part of the lambda’s response JSON – Output is base64-encoded – CircleCI build script collates outputs from all build-lambda invocations within a build, then uploads them to Coveralls • If a test fails, lambda invocation fails – This failure is detected by the CircleCI build scripts, which take appropriate actions 6
  • 7. Building • We use “go build” to build the binary • Code dependencies are vendored and stored in the repository • Built binary is uploaded to an S3 bucket specified in the event JSON, using the Python AWS SDK 7
  • 8. Invoking the build lambda from the CI • Depend on convention to separate function code and shared code • Iterate through all directories containing code: – Invoke build-lambda in test-only mode for shared code – Invoke build-lambda in test+build mode for function code • Use GNU Parallel to invoke build-lambda simultaneously – Build AWS CLI commands for each invocation, save to file – Pipe saved file through GNU Parallel to run commands in parallel – Halt build if any build-lambda invocation fails • Use JQ to parse lambda’s invocation result from AWS, and take appropriate actions: – Build error if .FunctionError is not null – Base64-decode test coverage output and append to Coveralls – Output .LogResult to STDOUT if .FunctionError is not null 8
  • 9. Logging • The build-lambda logs to Cloudwatch • The CircleCI script invokes the build-lambda using the “--log-type Tail” AWS CLI option – This returns a field in the result named ”.LogResult” – Contains the last 4K of logs, base64-encoded • If the invocation failed, then the CircleCI script outputs the base64-decoded contents of “.LogResult” to STDOUT • Build errors can be easily viewed on the CircleCI build output view • Further log processing can be done using Cloudwatch 9
  • 10. Deploying built binaries to functions • Use AWS CLI’s “update-function-code” command • Directly deploy from S3 without need for file transfers • Integration tests performed by downloading binaries from S3 into the CircleCI environment, and running tests against them – This ensures that the actual binary that was tested is deployed to the lambda function 10
  • 11. Q & A Q & A 11