SlideShare a Scribd company logo
1 of 51
Download to read offline
Building and running Spring Cloud-based
microservices on AWS ECS
Joris Kuipers
@jkuipers
About Me
 Joris Kuipers
 @jkuipers
 CTO of application development,
hands-on architect and
fly-by-night Spring trainer
@ Trifork Amsterdam
Setting The Stage
“When we are born we cry that we are come to this great stage of fools.”
― William Shakespeare
Introduction
 Integration project for
Dutch Loteries
 Started Q4 2017
 Expose suite of new backend systems to clients
 Provide APIs based on custom domain model
 Encapsulate backend details
 Facilitate future replacement
Architecture
 Separate domains
(verticals)
and service types
(horizontals)
 Verticals:
specific games,
subscriptions, players, …
Project Setup
 Every service is Spring Cloud app
 Blocking HTTP for inter-service communication
 Too early for reactive
 Hystrix for circuit breaking
 Mono-repo using Gradle build
 More services than teams
 Easy to have shared libs
 Can extract later
Technology
 Services run in Docker Container on AWS ECS
 Consul for service discovery and shared config
 Provisioning with Terraform
 Use as-a-service for CI/CD
AWS ECS
 Elastic Container Service
 Docker container scheduling / orchestration
 Placement on EC2 hosts
 Adding / removing instances
 Includes Docker Registry:
ECR
Expectations
 Fairly late adopters of Cloud and Docker
 Some plain EC2 experience with AWS
 Some Kubernetes experience on private DC
 AWS is nr. 1 cloud: ECS will just work
 Without much custom ops
 Services and tasks: similar to K8S
Chapter 1: ECS vs EC2
“We are responsible for actions performed in response to
circumstances for which we are not responsible”
― Allan Massie
How ECS Works
 You configure and pay for EC2 hosts
 ECS is free service using those hosts
 Runs Container Agent as Docker container
 Dedicated AMI, or install yourself
Scaling ECS vs EC2
 With ECS, can scale nr of containers for a task
 Based on alarms like % CPU
 However, may require additional EC2 capacity
 Autoscaling no good for scaling down
 Don’t want to kill EC2 instances w/ active containers
 Drain frst
 Need to manually control this w/ lambda
Fargate
 Announced late 2017
 Containers 1st class citizen
 No need to manage your own EC2 instances
 Only available in US East initially
 No way to SSH into your instance anymore
Chapter 2: Consul
“Consul - in American politics, a person who having failed to
secure an office from the people is given one by the
Administration on condition that he leave the country.”
― Ambrose Bierce
HashiCorp’s Consul
 Service Discovery
 Configuration through K/V store
 Excellent Spring Cloud Support
 Just worked when first deploying 3 services
 Stopped working when adding more
ECS Networking
 Bridged networking: docker0 to EC2 host
 Communication between Dockers via
host IP and port
 Binding to host port dynamic
 We were using local IP and port
 Need to discover host IP and port at startup…
Discover Host
 IP can be accessed from URL
 http://169.254.169.254/latest/meta-data/local-ipv4/
if curl -s -q http://169.254.169.254 --connect-timeout 0.5 > /dev/null; then
export SPRING_CLOUD_CONSUL_DISCOVERY_IP_ADDRESS=
$( curl -s http://169.254.169.254/latest/meta-data/local-ipv4/ )
fi
Discover Port Binding
 Port binding is in metadata file
 JSON file, path available via env. Variable
 Feature since Nov. ’17: first enable
 Have to parse the JSON
# Wait until container metadata is complete
until grep "ContainerID" $ECS_CONTAINER_METADATA_FILE > /dev/null; do sleep 1; done
export SPRING_CLOUD_CONSUL_DISCOVERY_PORT=$( cat $ECS_CONTAINER_METADATA_FILE | 
jq -r ".PortMappings[] .HostPort" )
Port Binding Discovery before Nov. ’17
Configuring Consul Instance ID
 Used to register service instance with Consul
 Needs to be unique per instance!
 Defaults to ${spring.application.name}:${server.port}
 But within Docker, our server port is always 8080
 Multiple instances overwrite each other
spring.cloud.consul.discovery.instance-id=
${spring.application.name}-${SPRING_CLOUD_CONSUL_DISCOVERY_PORT:${server.port}}
Consul as Config Server
 Built-in K/V store supported by Spring Cloud
 Individual properties, or file per service
 Supports shared configuration
 Idea: populate from Git repo (git2consul)
 Problem: passwords
Chapter 3: AWS Parameter Store
“In the absence of the gold standard, there is no way to
protect savings from confiscation through inflation. There is
no safe store of value.”
― Alan Greenspan
AWS Systems Manager
Parameter Store
 String K/V store, part of EC2
 Supports nested names
 Since June ’17
 Supports encryption of secrets
 Versioning
 Access controlled through IAM
AWS Parameter Store
Spring Cloud Parameter Store
support
 Looked like great solution
 Hierarchical paths allow config per env. / service &
shared config, like with Consul
 IAM Security, Java & Terraform API support, …
 But no Spring Cloud support, only open issue
 No support yet
Spring Cloud Config Clients
 Implement PropertySourceLocator
 CompositePropertySource: ordered list of
PropertySources for:
 Shared config (/application/…)
 Service-specific config (/<service-name>/…)
 Incl. per-profile config (/<service-name>,<profile>/…)
PropertySource<?> locate(Environment environment);
Implementing Parameter Store
Support
 PropertySourceLocator:
Mostly copied from Consul support
 No support for whole files
 Param Store value max. 4K chars
 Only real work: implement PropertySource
 Using AWS Java SDK
 AWSSimpleSystemsManagement client
public class AwsParamStorePropertySource extends EnumerablePropertySource<AWSSimpleSystemsManagement> {
private String context;
private Map<String, Object> properties = new LinkedHashMap<>();
public AwsParamStorePropertySource(String context, AWSSimpleSystemsManagement ssmClient) {
super(context, ssmClient);
this.context = context;
}
public void init() {
GetParametersByPathRequest paramsRequest = new GetParametersByPathRequest()
.withPath(context).withRecursive(true).withWithDecryption(true);
getParameters(paramsRequest);
}
@Override public String[] getPropertyNames() {
Set<String> strings = properties.keySet();
return strings.toArray(new String[strings.size()]);
}
@Override public Object getProperty(String name) { return properties.get(name); }
private void getParameters(GetParametersByPathRequest paramsRequest) {
GetParametersByPathResult paramsResult = source.getParametersByPath(paramsRequest);
for (Parameter parameter : paramsResult.getParameters()) {
String key = parameter.getName().replace(context, "").replace('/', '.');
properties.put(key, parameter.getValue());
}
if (paramsResult.getNextToken() != null) {
getParameters(paramsRequest.withNextToken(paramsResult.getNextToken()));
}
}
}
Wrapping up
 Add BootstrapConfiguration and type-safe
properties classes for Spring Cloud
 Configure per-environment support in
bootstrap.properties of every service:
 Contributed pull request
aws.paramstore.prefix=/config-${ENVIRONMENT}
Chapter 4: Service Discovery
“Mistakes are the portals of discovery.”
― James Joyce
Health Checks in ECS
 Started out with just external load balancer
 ECS needed internal one as well,
just for container health checks
 Might as well use for inter-service communication
 With Parameter Store, made Consul obsolete
AWS Advancements
 March 2018: ECS supports Docker health checks
 ELB no longer required
 Also March 2018: ECS Service Discovery
 Route 53 Auto Naming API
 Only returns healthy services
 No need for custom service registry or internal LB
 Requires awsvpc, not in all regions yet
 UPDATE: after this presentation, AWS announced this
AWSVPC
 “Cloud-native” Networking mode
 Alternative to bridged
 Introduced Nov. ’17
 Full networking features for ECS Tasks
 Security groups, network monitoring, direct IPs
 Optional using EC2, required for Fargate
AWSVPC Small Print
ECS Service Discovery
 Not using this yet
 Seems good candidate for Spring Cloud Support
 Discover all healthy instances
 Provide client-side load balancing through Ribbon
 Real benefits over internal LB
 Saves network hops and thus latency
Ribbon & Server-side Load Balancing
 Keeping Ribbon for now
 Might move to service discovery
 Just configure DNS name for downstream service
lotto.system-url=http://lotto-system
lotto-system.ribbon.listOfServers=lotto-system.nlogateway.vpc
@Bean @LoadBalanced
RestTemplate restTemplate(RestTemplateBuilder builder,
@Value("${lotto.system-url}") String serviceUrl)
{
return builder.rootUri(serviceUrl).build();
}
Ribbon & Zuul Configuration
 Using Ribbon facilitates Zuul proxy config as well
zuul:
ignoredServices: '*'
# proxy anything except for these, handled locally:
ignoredPatterns:
- /actuator/**
- /error
- /lotto/productOrder*
routes:
lotto-system:
path: /**
serviceId: lotto-system
Service, not URL
Chapter 4: Logging and Tracing
“To acquire knowledge, one must study;
but to acquire wisdom, one must observe.”
― Marilyn vos Savant
Logging
 Using logback-spring.xml for Logback config
 Allows accessing spring properties
 No need for reloading config
 Currently using logz.io
 ELK-based logging as a service provider
 Provides Logback appender
logback-spring.xml
<configuration>
<property name="environment" value="${ENVIRONMENT:-local}"/>
<include resource="org/sfw/boot/logging/logback/defaults.xml" />
<include resource="org/sfw/boot/logging/logback/console-appender.xml" />
<include resource="logzio-appender.xml" />
…
<root level="INFO">
<if condition='property("environment").equals("local")'>
<then><appender-ref ref="CONSOLE"/></then>
<else><appender-ref ref="LogzioAppender"/></else>
</if>
</root>
</configuration>
logzio-appender.xml
<included>
<springProperty name="service" source="spring.application.name/>
<springProperty name="version" source="gw.version" defaultValue="unknown"/>
<define name="awsRegion"
class="nlo.gateway.logging.AwsRegionPropertyDefiner"/>
<appender name="LogzioAppender"
class="io.logz.logback.LogzioLogbackAppender">
…
<additionalFields>environment=${environment};service=${service};
version=${version};aws_region=${awsRegion}</additionalFields>
</appender>
…
</included>
Logback PropertyProvider
import ch.qos.logback.core.PropertyDefinerBase;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
public class AwsRegionPropertyDefiner extends PropertyDefinerBase {
@Override
public String getPropertyValue() {
Region currentRegion = Regions.getCurrentRegion();
return currentRegion != null ? currentRegion.getName() : "-";
}
}
Distributed Tracing
 Spring Sleuth allows distribute tracing
 Propagating correlation ID per logical request
 Uses OpenZipkin’s Brave
 Instruments many Spring components
SLF4J MDC Integration
Brave vs. AMZN Trace IDs
 AWS LBs can add X-AMZN-Trace-ID header
 Format incompatible with Brave’s Trace ID
 Self=1-67891234-12456789abcdef012345678;Root=1-
67891233-abcdef012345678912345678
 However, easy to forward through Sleuth:
 Extracting and logging root trace ID slightly trickier
 Custom Slf4jCurrentTraceContext impl
 Override beans from SleuthLogAutoConfiguration
spring.sleuth.propagation-keys=X-Amzn-Trace-Id
Bootstrap Logging
 Initial bootstrap Logging not done via Logback
 Might prevent seeing cause of startup errors
 Enable Logging for ECS tasks, e.g. via docker-compose:
services:
lotto-experience:
logging:
driver: awslogs
options:
awslogs-group: ${AWSLOGS_GROUP}
awslogs-stream-prefix: lotto
Metrics
 Boot 2.0 ships with Micrometer integration
 Metrics façade: SLF4J for metrics
 Instruments many Spring components
 Using this with Datadog
Common Tags + Hystrix Metrics
@Bean
MeterRegistryCustomizer<MeterRegistry> commonTags(Environment env) {
Region awsRegion = Regions.getCurrentRegion();
return registry -> registry.config().commonTags(
"service", env.getProperty("spring.application.name),
"environment", env.getProperty("environment", "local"),
"version", env.getProperty("gw.version", "unknown-version"),
"aws_region", awsRegion != null ? awsRegion.getName() : "-"
);
}
@Bean HystrixMetricsBinder hystrixMetricsBinder() {
return new HystrixMetricsBinder();
}
Think About Cardinality
 Reduce possible values for metrics tags
 HTTP metrics include URI
@Bean
MeterFilter queryParameterStrippingMeterFilter() {
return MeterFilter.replaceTagValues("uri", url -> {
int i = url.indexOf('?');
return i == -1 ? url : url.substring(0, i);
});
}
Conclusion
 AWS Docker support less mature than expected
 Lots of improvements all the time, though
 Including Kubernetes support: EKS
 Spring Cloud provides tons of great features
 Central config, service discovery, tracing
 Easy to add custom implementations
THANKS!
Q & A
Joris Kuipers
@jkuipers

More Related Content

What's hot

ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewShahed Chowdhuri
 
Kubernetes best practices with GKE
Kubernetes best practices with GKEKubernetes best practices with GKE
Kubernetes best practices with GKEGDG Cloud Bengaluru
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass SlidesNir Kaufman
 
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기흥배 최
 
오딘: 발할라 라이징 MMORPG의 성능 최적화 사례 공유 [카카오게임즈 - 레벨 300] - 발표자: 김문권, 팀장, 라이온하트 스튜디오...
오딘: 발할라 라이징 MMORPG의 성능 최적화 사례 공유 [카카오게임즈 - 레벨 300] - 발표자: 김문권, 팀장, 라이온하트 스튜디오...오딘: 발할라 라이징 MMORPG의 성능 최적화 사례 공유 [카카오게임즈 - 레벨 300] - 발표자: 김문권, 팀장, 라이온하트 스튜디오...
오딘: 발할라 라이징 MMORPG의 성능 최적화 사례 공유 [카카오게임즈 - 레벨 300] - 발표자: 김문권, 팀장, 라이온하트 스튜디오...Amazon Web Services Korea
 
Docker swarm introduction
Docker swarm introductionDocker swarm introduction
Docker swarm introductionEvan Lin
 
What Is React | ReactJS Tutorial for Beginners | ReactJS Training | Edureka
What Is React | ReactJS Tutorial for Beginners | ReactJS Training | EdurekaWhat Is React | ReactJS Tutorial for Beginners | ReactJS Training | Edureka
What Is React | ReactJS Tutorial for Beginners | ReactJS Training | EdurekaEdureka!
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
이승재, 마비노기 듀얼: 분산 데이터베이스 트랜잭션 설계와 구현, NDC2015
이승재, 마비노기 듀얼: 분산 데이터베이스 트랜잭션 설계와 구현, NDC2015이승재, 마비노기 듀얼: 분산 데이터베이스 트랜잭션 설계와 구현, NDC2015
이승재, 마비노기 듀얼: 분산 데이터베이스 트랜잭션 설계와 구현, NDC2015devCAT Studio, NEXON
 
Deep Dive into Docker Swarm Mode
Deep Dive into Docker Swarm ModeDeep Dive into Docker Swarm Mode
Deep Dive into Docker Swarm ModeAjeet Singh Raina
 
YOW2018 Cloud Performance Root Cause Analysis at Netflix
YOW2018 Cloud Performance Root Cause Analysis at NetflixYOW2018 Cloud Performance Root Cause Analysis at Netflix
YOW2018 Cloud Performance Root Cause Analysis at NetflixBrendan Gregg
 
Comparison of Current Service Mesh Architectures
Comparison of Current Service Mesh ArchitecturesComparison of Current Service Mesh Architectures
Comparison of Current Service Mesh ArchitecturesMirantis
 
Rest API with Swagger and NodeJS
Rest API with Swagger and NodeJSRest API with Swagger and NodeJS
Rest API with Swagger and NodeJSLuigi Saetta
 
Jakarta EE 8: Overview of Features
Jakarta EE 8: Overview of FeaturesJakarta EE 8: Overview of Features
Jakarta EE 8: Overview of FeaturesJosh Juneau
 
대용량 분산 아키텍쳐 설계 #5. rest
대용량 분산 아키텍쳐 설계 #5. rest대용량 분산 아키텍쳐 설계 #5. rest
대용량 분산 아키텍쳐 설계 #5. restTerry Cho
 
Kubernetes Introduction
Kubernetes IntroductionKubernetes Introduction
Kubernetes IntroductionPeng Xiao
 

What's hot (20)

Flux architecture
Flux architectureFlux architecture
Flux architecture
 
API Docs with OpenAPI 3.0
API Docs with OpenAPI 3.0API Docs with OpenAPI 3.0
API Docs with OpenAPI 3.0
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
Kubernetes best practices with GKE
Kubernetes best practices with GKEKubernetes best practices with GKE
Kubernetes best practices with GKE
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
 
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
 
오딘: 발할라 라이징 MMORPG의 성능 최적화 사례 공유 [카카오게임즈 - 레벨 300] - 발표자: 김문권, 팀장, 라이온하트 스튜디오...
오딘: 발할라 라이징 MMORPG의 성능 최적화 사례 공유 [카카오게임즈 - 레벨 300] - 발표자: 김문권, 팀장, 라이온하트 스튜디오...오딘: 발할라 라이징 MMORPG의 성능 최적화 사례 공유 [카카오게임즈 - 레벨 300] - 발표자: 김문권, 팀장, 라이온하트 스튜디오...
오딘: 발할라 라이징 MMORPG의 성능 최적화 사례 공유 [카카오게임즈 - 레벨 300] - 발표자: 김문권, 팀장, 라이온하트 스튜디오...
 
Docker swarm introduction
Docker swarm introductionDocker swarm introduction
Docker swarm introduction
 
What Is React | ReactJS Tutorial for Beginners | ReactJS Training | Edureka
What Is React | ReactJS Tutorial for Beginners | ReactJS Training | EdurekaWhat Is React | ReactJS Tutorial for Beginners | ReactJS Training | Edureka
What Is React | ReactJS Tutorial for Beginners | ReactJS Training | Edureka
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Docker and Devops
Docker and DevopsDocker and Devops
Docker and Devops
 
이승재, 마비노기 듀얼: 분산 데이터베이스 트랜잭션 설계와 구현, NDC2015
이승재, 마비노기 듀얼: 분산 데이터베이스 트랜잭션 설계와 구현, NDC2015이승재, 마비노기 듀얼: 분산 데이터베이스 트랜잭션 설계와 구현, NDC2015
이승재, 마비노기 듀얼: 분산 데이터베이스 트랜잭션 설계와 구현, NDC2015
 
Deep Dive into Docker Swarm Mode
Deep Dive into Docker Swarm ModeDeep Dive into Docker Swarm Mode
Deep Dive into Docker Swarm Mode
 
YOW2018 Cloud Performance Root Cause Analysis at Netflix
YOW2018 Cloud Performance Root Cause Analysis at NetflixYOW2018 Cloud Performance Root Cause Analysis at Netflix
YOW2018 Cloud Performance Root Cause Analysis at Netflix
 
Comparison of Current Service Mesh Architectures
Comparison of Current Service Mesh ArchitecturesComparison of Current Service Mesh Architectures
Comparison of Current Service Mesh Architectures
 
Springboot Overview
Springboot  OverviewSpringboot  Overview
Springboot Overview
 
Rest API with Swagger and NodeJS
Rest API with Swagger and NodeJSRest API with Swagger and NodeJS
Rest API with Swagger and NodeJS
 
Jakarta EE 8: Overview of Features
Jakarta EE 8: Overview of FeaturesJakarta EE 8: Overview of Features
Jakarta EE 8: Overview of Features
 
대용량 분산 아키텍쳐 설계 #5. rest
대용량 분산 아키텍쳐 설계 #5. rest대용량 분산 아키텍쳐 설계 #5. rest
대용량 분산 아키텍쳐 설계 #5. rest
 
Kubernetes Introduction
Kubernetes IntroductionKubernetes Introduction
Kubernetes Introduction
 

Similar to Building and running Spring Cloud-based microservices on AWS ECS

Kubernetes and Amazon ECS
Kubernetes and Amazon ECSKubernetes and Amazon ECS
Kubernetes and Amazon ECSGeert Pante
 
Max Körbächer - AWS EKS and beyond – master your Kubernetes deployment on AWS...
Max Körbächer - AWS EKS and beyond – master your Kubernetes deployment on AWS...Max Körbächer - AWS EKS and beyond – master your Kubernetes deployment on AWS...
Max Körbächer - AWS EKS and beyond – master your Kubernetes deployment on AWS...Codemotion
 
Max Körbächer - AWS EKS and beyond master your Kubernetes deployment on AWS -...
Max Körbächer - AWS EKS and beyond master your Kubernetes deployment on AWS -...Max Körbächer - AWS EKS and beyond master your Kubernetes deployment on AWS -...
Max Körbächer - AWS EKS and beyond master your Kubernetes deployment on AWS -...Codemotion
 
Continuous Integration e Delivery per (r)innovare lo sviluppo software e la g...
Continuous Integration e Delivery per (r)innovare lo sviluppo software e la g...Continuous Integration e Delivery per (r)innovare lo sviluppo software e la g...
Continuous Integration e Delivery per (r)innovare lo sviluppo software e la g...Amazon Web Services
 
Getting Started with Docker On AWS
Getting Started with Docker On AWSGetting Started with Docker On AWS
Getting Started with Docker On AWSAmazon Web Services
 
AWS Elastic Beanstalk - Running Microservices and Docker
AWS Elastic Beanstalk - Running Microservices and DockerAWS Elastic Beanstalk - Running Microservices and Docker
AWS Elastic Beanstalk - Running Microservices and DockerAmazon Web Services
 
Bitbucket Pipelines - Powered by Kubernetes
Bitbucket Pipelines - Powered by KubernetesBitbucket Pipelines - Powered by Kubernetes
Bitbucket Pipelines - Powered by KubernetesNathan Burrell
 
From Docker Straight to AWS
From Docker Straight to AWSFrom Docker Straight to AWS
From Docker Straight to AWSDevOps.com
 
Advanced Container Management and Scheduling
Advanced Container Management and SchedulingAdvanced Container Management and Scheduling
Advanced Container Management and SchedulingAmazon Web Services
 
Deliver Docker Containers Continuously on AWS - QCon 2017
Deliver Docker Containers Continuously on AWS - QCon 2017Deliver Docker Containers Continuously on AWS - QCon 2017
Deliver Docker Containers Continuously on AWS - QCon 2017Philipp Garbe
 
AWS Webcast - Getting Started with AWS OpsWorks
AWS Webcast - Getting Started with AWS OpsWorksAWS Webcast - Getting Started with AWS OpsWorks
AWS Webcast - Getting Started with AWS OpsWorksAmazon Web Services
 
Amazon ECS with Docker | AWS Public Sector Summit 2016
Amazon ECS with Docker | AWS Public Sector Summit 2016Amazon ECS with Docker | AWS Public Sector Summit 2016
Amazon ECS with Docker | AWS Public Sector Summit 2016Amazon Web Services
 
A 60-mn tour of AWS compute (March 2016)
A 60-mn tour of AWS compute (March 2016)A 60-mn tour of AWS compute (March 2016)
A 60-mn tour of AWS compute (March 2016)Julien SIMON
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to KubernetesPaul Czarkowski
 
Running containerized application in AWS ECS
Running containerized application in AWS ECSRunning containerized application in AWS ECS
Running containerized application in AWS ECSDevOps Indonesia
 
Aws + kubernetes = ❤︎
Aws + kubernetes = ❤︎Aws + kubernetes = ❤︎
Aws + kubernetes = ❤︎Anthony Stanton
 
Getting Started with Docker on AWS - DevDay Los Angeles 2017
Getting Started with Docker on AWS - DevDay Los Angeles 2017Getting Started with Docker on AWS - DevDay Los Angeles 2017
Getting Started with Docker on AWS - DevDay Los Angeles 2017Amazon Web Services
 
無伺服器架構和Containers on AWS入門
無伺服器架構和Containers on AWS入門 無伺服器架構和Containers on AWS入門
無伺服器架構和Containers on AWS入門 Amazon Web Services
 

Similar to Building and running Spring Cloud-based microservices on AWS ECS (20)

Kubernetes and Amazon ECS
Kubernetes and Amazon ECSKubernetes and Amazon ECS
Kubernetes and Amazon ECS
 
Max Körbächer - AWS EKS and beyond – master your Kubernetes deployment on AWS...
Max Körbächer - AWS EKS and beyond – master your Kubernetes deployment on AWS...Max Körbächer - AWS EKS and beyond – master your Kubernetes deployment on AWS...
Max Körbächer - AWS EKS and beyond – master your Kubernetes deployment on AWS...
 
Max Körbächer - AWS EKS and beyond master your Kubernetes deployment on AWS -...
Max Körbächer - AWS EKS and beyond master your Kubernetes deployment on AWS -...Max Körbächer - AWS EKS and beyond master your Kubernetes deployment on AWS -...
Max Körbächer - AWS EKS and beyond master your Kubernetes deployment on AWS -...
 
Continuous Integration e Delivery per (r)innovare lo sviluppo software e la g...
Continuous Integration e Delivery per (r)innovare lo sviluppo software e la g...Continuous Integration e Delivery per (r)innovare lo sviluppo software e la g...
Continuous Integration e Delivery per (r)innovare lo sviluppo software e la g...
 
Getting Started with Docker On AWS
Getting Started with Docker On AWSGetting Started with Docker On AWS
Getting Started with Docker On AWS
 
Shipping logs to splunk from a container in aws howto
Shipping logs to splunk from a container in aws howtoShipping logs to splunk from a container in aws howto
Shipping logs to splunk from a container in aws howto
 
AWS Elastic Beanstalk - Running Microservices and Docker
AWS Elastic Beanstalk - Running Microservices and DockerAWS Elastic Beanstalk - Running Microservices and Docker
AWS Elastic Beanstalk - Running Microservices and Docker
 
Advanced Container Scheduling
Advanced Container SchedulingAdvanced Container Scheduling
Advanced Container Scheduling
 
Bitbucket Pipelines - Powered by Kubernetes
Bitbucket Pipelines - Powered by KubernetesBitbucket Pipelines - Powered by Kubernetes
Bitbucket Pipelines - Powered by Kubernetes
 
From Docker Straight to AWS
From Docker Straight to AWSFrom Docker Straight to AWS
From Docker Straight to AWS
 
Advanced Container Management and Scheduling
Advanced Container Management and SchedulingAdvanced Container Management and Scheduling
Advanced Container Management and Scheduling
 
Deliver Docker Containers Continuously on AWS - QCon 2017
Deliver Docker Containers Continuously on AWS - QCon 2017Deliver Docker Containers Continuously on AWS - QCon 2017
Deliver Docker Containers Continuously on AWS - QCon 2017
 
AWS Webcast - Getting Started with AWS OpsWorks
AWS Webcast - Getting Started with AWS OpsWorksAWS Webcast - Getting Started with AWS OpsWorks
AWS Webcast - Getting Started with AWS OpsWorks
 
Amazon ECS with Docker | AWS Public Sector Summit 2016
Amazon ECS with Docker | AWS Public Sector Summit 2016Amazon ECS with Docker | AWS Public Sector Summit 2016
Amazon ECS with Docker | AWS Public Sector Summit 2016
 
A 60-mn tour of AWS compute (March 2016)
A 60-mn tour of AWS compute (March 2016)A 60-mn tour of AWS compute (March 2016)
A 60-mn tour of AWS compute (March 2016)
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to Kubernetes
 
Running containerized application in AWS ECS
Running containerized application in AWS ECSRunning containerized application in AWS ECS
Running containerized application in AWS ECS
 
Aws + kubernetes = ❤︎
Aws + kubernetes = ❤︎Aws + kubernetes = ❤︎
Aws + kubernetes = ❤︎
 
Getting Started with Docker on AWS - DevDay Los Angeles 2017
Getting Started with Docker on AWS - DevDay Los Angeles 2017Getting Started with Docker on AWS - DevDay Los Angeles 2017
Getting Started with Docker on AWS - DevDay Los Angeles 2017
 
無伺服器架構和Containers on AWS入門
無伺服器架構和Containers on AWS入門 無伺服器架構和Containers on AWS入門
無伺服器架構和Containers on AWS入門
 

More from Joris Kuipers

Action Jackson! Effective JSON processing in Spring Boot Applications
Action Jackson! Effective JSON processing in Spring Boot ApplicationsAction Jackson! Effective JSON processing in Spring Boot Applications
Action Jackson! Effective JSON processing in Spring Boot ApplicationsJoris Kuipers
 
Hearts Of Darkness - a Spring DevOps Apocalypse
Hearts Of Darkness - a Spring DevOps ApocalypseHearts Of Darkness - a Spring DevOps Apocalypse
Hearts Of Darkness - a Spring DevOps ApocalypseJoris Kuipers
 
I Can See Clearly Now - Observing & understanding your Spring applications at...
I Can See Clearly Now - Observing & understanding your Spring applications at...I Can See Clearly Now - Observing & understanding your Spring applications at...
I Can See Clearly Now - Observing & understanding your Spring applications at...Joris Kuipers
 
Day 2 Problems in CQRS & Event Sourcing
Day 2 Problems in CQRS & Event SourcingDay 2 Problems in CQRS & Event Sourcing
Day 2 Problems in CQRS & Event SourcingJoris Kuipers
 
Booting your Microservices Architecture with Spring & Netflix
Booting your Microservices Architecture with Spring & NetflixBooting your Microservices Architecture with Spring & Netflix
Booting your Microservices Architecture with Spring & NetflixJoris Kuipers
 
Building Layers of Defense with Spring Security
Building Layers of Defense with Spring SecurityBuilding Layers of Defense with Spring Security
Building Layers of Defense with Spring SecurityJoris Kuipers
 
Come Fly With Me: Database Migration Patterns with Flyway
Come Fly With Me: Database Migration Patterns with FlywayCome Fly With Me: Database Migration Patterns with Flyway
Come Fly With Me: Database Migration Patterns with FlywayJoris Kuipers
 

More from Joris Kuipers (8)

Action Jackson! Effective JSON processing in Spring Boot Applications
Action Jackson! Effective JSON processing in Spring Boot ApplicationsAction Jackson! Effective JSON processing in Spring Boot Applications
Action Jackson! Effective JSON processing in Spring Boot Applications
 
Hearts Of Darkness - a Spring DevOps Apocalypse
Hearts Of Darkness - a Spring DevOps ApocalypseHearts Of Darkness - a Spring DevOps Apocalypse
Hearts Of Darkness - a Spring DevOps Apocalypse
 
I Can See Clearly Now - Observing & understanding your Spring applications at...
I Can See Clearly Now - Observing & understanding your Spring applications at...I Can See Clearly Now - Observing & understanding your Spring applications at...
I Can See Clearly Now - Observing & understanding your Spring applications at...
 
Day 2 Problems in CQRS & Event Sourcing
Day 2 Problems in CQRS & Event SourcingDay 2 Problems in CQRS & Event Sourcing
Day 2 Problems in CQRS & Event Sourcing
 
Boot Loot
Boot LootBoot Loot
Boot Loot
 
Booting your Microservices Architecture with Spring & Netflix
Booting your Microservices Architecture with Spring & NetflixBooting your Microservices Architecture with Spring & Netflix
Booting your Microservices Architecture with Spring & Netflix
 
Building Layers of Defense with Spring Security
Building Layers of Defense with Spring SecurityBuilding Layers of Defense with Spring Security
Building Layers of Defense with Spring Security
 
Come Fly With Me: Database Migration Patterns with Flyway
Come Fly With Me: Database Migration Patterns with FlywayCome Fly With Me: Database Migration Patterns with Flyway
Come Fly With Me: Database Migration Patterns with Flyway
 

Recently uploaded

PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 

Recently uploaded (20)

PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 

Building and running Spring Cloud-based microservices on AWS ECS

  • 1. Building and running Spring Cloud-based microservices on AWS ECS Joris Kuipers @jkuipers
  • 2. About Me  Joris Kuipers  @jkuipers  CTO of application development, hands-on architect and fly-by-night Spring trainer @ Trifork Amsterdam
  • 3. Setting The Stage “When we are born we cry that we are come to this great stage of fools.” ― William Shakespeare
  • 4. Introduction  Integration project for Dutch Loteries  Started Q4 2017  Expose suite of new backend systems to clients  Provide APIs based on custom domain model  Encapsulate backend details  Facilitate future replacement
  • 5. Architecture  Separate domains (verticals) and service types (horizontals)  Verticals: specific games, subscriptions, players, …
  • 6. Project Setup  Every service is Spring Cloud app  Blocking HTTP for inter-service communication  Too early for reactive  Hystrix for circuit breaking  Mono-repo using Gradle build  More services than teams  Easy to have shared libs  Can extract later
  • 7. Technology  Services run in Docker Container on AWS ECS  Consul for service discovery and shared config  Provisioning with Terraform  Use as-a-service for CI/CD
  • 8. AWS ECS  Elastic Container Service  Docker container scheduling / orchestration  Placement on EC2 hosts  Adding / removing instances  Includes Docker Registry: ECR
  • 9. Expectations  Fairly late adopters of Cloud and Docker  Some plain EC2 experience with AWS  Some Kubernetes experience on private DC  AWS is nr. 1 cloud: ECS will just work  Without much custom ops  Services and tasks: similar to K8S
  • 10. Chapter 1: ECS vs EC2 “We are responsible for actions performed in response to circumstances for which we are not responsible” ― Allan Massie
  • 11. How ECS Works  You configure and pay for EC2 hosts  ECS is free service using those hosts  Runs Container Agent as Docker container  Dedicated AMI, or install yourself
  • 12. Scaling ECS vs EC2  With ECS, can scale nr of containers for a task  Based on alarms like % CPU  However, may require additional EC2 capacity  Autoscaling no good for scaling down  Don’t want to kill EC2 instances w/ active containers  Drain frst  Need to manually control this w/ lambda
  • 13. Fargate  Announced late 2017  Containers 1st class citizen  No need to manage your own EC2 instances  Only available in US East initially  No way to SSH into your instance anymore
  • 14. Chapter 2: Consul “Consul - in American politics, a person who having failed to secure an office from the people is given one by the Administration on condition that he leave the country.” ― Ambrose Bierce
  • 15. HashiCorp’s Consul  Service Discovery  Configuration through K/V store  Excellent Spring Cloud Support  Just worked when first deploying 3 services  Stopped working when adding more
  • 16. ECS Networking  Bridged networking: docker0 to EC2 host  Communication between Dockers via host IP and port  Binding to host port dynamic  We were using local IP and port  Need to discover host IP and port at startup…
  • 17. Discover Host  IP can be accessed from URL  http://169.254.169.254/latest/meta-data/local-ipv4/ if curl -s -q http://169.254.169.254 --connect-timeout 0.5 > /dev/null; then export SPRING_CLOUD_CONSUL_DISCOVERY_IP_ADDRESS= $( curl -s http://169.254.169.254/latest/meta-data/local-ipv4/ ) fi
  • 18. Discover Port Binding  Port binding is in metadata file  JSON file, path available via env. Variable  Feature since Nov. ’17: first enable  Have to parse the JSON # Wait until container metadata is complete until grep "ContainerID" $ECS_CONTAINER_METADATA_FILE > /dev/null; do sleep 1; done export SPRING_CLOUD_CONSUL_DISCOVERY_PORT=$( cat $ECS_CONTAINER_METADATA_FILE | jq -r ".PortMappings[] .HostPort" )
  • 19. Port Binding Discovery before Nov. ’17
  • 20. Configuring Consul Instance ID  Used to register service instance with Consul  Needs to be unique per instance!  Defaults to ${spring.application.name}:${server.port}  But within Docker, our server port is always 8080  Multiple instances overwrite each other spring.cloud.consul.discovery.instance-id= ${spring.application.name}-${SPRING_CLOUD_CONSUL_DISCOVERY_PORT:${server.port}}
  • 21. Consul as Config Server  Built-in K/V store supported by Spring Cloud  Individual properties, or file per service  Supports shared configuration  Idea: populate from Git repo (git2consul)  Problem: passwords
  • 22. Chapter 3: AWS Parameter Store “In the absence of the gold standard, there is no way to protect savings from confiscation through inflation. There is no safe store of value.” ― Alan Greenspan
  • 23. AWS Systems Manager Parameter Store  String K/V store, part of EC2  Supports nested names  Since June ’17  Supports encryption of secrets  Versioning  Access controlled through IAM
  • 25. Spring Cloud Parameter Store support  Looked like great solution  Hierarchical paths allow config per env. / service & shared config, like with Consul  IAM Security, Java & Terraform API support, …  But no Spring Cloud support, only open issue  No support yet
  • 26. Spring Cloud Config Clients  Implement PropertySourceLocator  CompositePropertySource: ordered list of PropertySources for:  Shared config (/application/…)  Service-specific config (/<service-name>/…)  Incl. per-profile config (/<service-name>,<profile>/…) PropertySource<?> locate(Environment environment);
  • 27. Implementing Parameter Store Support  PropertySourceLocator: Mostly copied from Consul support  No support for whole files  Param Store value max. 4K chars  Only real work: implement PropertySource  Using AWS Java SDK  AWSSimpleSystemsManagement client
  • 28. public class AwsParamStorePropertySource extends EnumerablePropertySource<AWSSimpleSystemsManagement> { private String context; private Map<String, Object> properties = new LinkedHashMap<>(); public AwsParamStorePropertySource(String context, AWSSimpleSystemsManagement ssmClient) { super(context, ssmClient); this.context = context; } public void init() { GetParametersByPathRequest paramsRequest = new GetParametersByPathRequest() .withPath(context).withRecursive(true).withWithDecryption(true); getParameters(paramsRequest); } @Override public String[] getPropertyNames() { Set<String> strings = properties.keySet(); return strings.toArray(new String[strings.size()]); } @Override public Object getProperty(String name) { return properties.get(name); } private void getParameters(GetParametersByPathRequest paramsRequest) { GetParametersByPathResult paramsResult = source.getParametersByPath(paramsRequest); for (Parameter parameter : paramsResult.getParameters()) { String key = parameter.getName().replace(context, "").replace('/', '.'); properties.put(key, parameter.getValue()); } if (paramsResult.getNextToken() != null) { getParameters(paramsRequest.withNextToken(paramsResult.getNextToken())); } } }
  • 29. Wrapping up  Add BootstrapConfiguration and type-safe properties classes for Spring Cloud  Configure per-environment support in bootstrap.properties of every service:  Contributed pull request aws.paramstore.prefix=/config-${ENVIRONMENT}
  • 30. Chapter 4: Service Discovery “Mistakes are the portals of discovery.” ― James Joyce
  • 31. Health Checks in ECS  Started out with just external load balancer  ECS needed internal one as well, just for container health checks  Might as well use for inter-service communication  With Parameter Store, made Consul obsolete
  • 32. AWS Advancements  March 2018: ECS supports Docker health checks  ELB no longer required  Also March 2018: ECS Service Discovery  Route 53 Auto Naming API  Only returns healthy services  No need for custom service registry or internal LB  Requires awsvpc, not in all regions yet  UPDATE: after this presentation, AWS announced this
  • 33. AWSVPC  “Cloud-native” Networking mode  Alternative to bridged  Introduced Nov. ’17  Full networking features for ECS Tasks  Security groups, network monitoring, direct IPs  Optional using EC2, required for Fargate
  • 35. ECS Service Discovery  Not using this yet  Seems good candidate for Spring Cloud Support  Discover all healthy instances  Provide client-side load balancing through Ribbon  Real benefits over internal LB  Saves network hops and thus latency
  • 36. Ribbon & Server-side Load Balancing  Keeping Ribbon for now  Might move to service discovery  Just configure DNS name for downstream service lotto.system-url=http://lotto-system lotto-system.ribbon.listOfServers=lotto-system.nlogateway.vpc @Bean @LoadBalanced RestTemplate restTemplate(RestTemplateBuilder builder, @Value("${lotto.system-url}") String serviceUrl) { return builder.rootUri(serviceUrl).build(); }
  • 37. Ribbon & Zuul Configuration  Using Ribbon facilitates Zuul proxy config as well zuul: ignoredServices: '*' # proxy anything except for these, handled locally: ignoredPatterns: - /actuator/** - /error - /lotto/productOrder* routes: lotto-system: path: /** serviceId: lotto-system Service, not URL
  • 38. Chapter 4: Logging and Tracing “To acquire knowledge, one must study; but to acquire wisdom, one must observe.” ― Marilyn vos Savant
  • 39. Logging  Using logback-spring.xml for Logback config  Allows accessing spring properties  No need for reloading config  Currently using logz.io  ELK-based logging as a service provider  Provides Logback appender
  • 40. logback-spring.xml <configuration> <property name="environment" value="${ENVIRONMENT:-local}"/> <include resource="org/sfw/boot/logging/logback/defaults.xml" /> <include resource="org/sfw/boot/logging/logback/console-appender.xml" /> <include resource="logzio-appender.xml" /> … <root level="INFO"> <if condition='property("environment").equals("local")'> <then><appender-ref ref="CONSOLE"/></then> <else><appender-ref ref="LogzioAppender"/></else> </if> </root> </configuration>
  • 41. logzio-appender.xml <included> <springProperty name="service" source="spring.application.name/> <springProperty name="version" source="gw.version" defaultValue="unknown"/> <define name="awsRegion" class="nlo.gateway.logging.AwsRegionPropertyDefiner"/> <appender name="LogzioAppender" class="io.logz.logback.LogzioLogbackAppender"> … <additionalFields>environment=${environment};service=${service}; version=${version};aws_region=${awsRegion}</additionalFields> </appender> … </included>
  • 42. Logback PropertyProvider import ch.qos.logback.core.PropertyDefinerBase; import com.amazonaws.regions.Region; import com.amazonaws.regions.Regions; public class AwsRegionPropertyDefiner extends PropertyDefinerBase { @Override public String getPropertyValue() { Region currentRegion = Regions.getCurrentRegion(); return currentRegion != null ? currentRegion.getName() : "-"; } }
  • 43. Distributed Tracing  Spring Sleuth allows distribute tracing  Propagating correlation ID per logical request  Uses OpenZipkin’s Brave  Instruments many Spring components
  • 45. Brave vs. AMZN Trace IDs  AWS LBs can add X-AMZN-Trace-ID header  Format incompatible with Brave’s Trace ID  Self=1-67891234-12456789abcdef012345678;Root=1- 67891233-abcdef012345678912345678  However, easy to forward through Sleuth:  Extracting and logging root trace ID slightly trickier  Custom Slf4jCurrentTraceContext impl  Override beans from SleuthLogAutoConfiguration spring.sleuth.propagation-keys=X-Amzn-Trace-Id
  • 46. Bootstrap Logging  Initial bootstrap Logging not done via Logback  Might prevent seeing cause of startup errors  Enable Logging for ECS tasks, e.g. via docker-compose: services: lotto-experience: logging: driver: awslogs options: awslogs-group: ${AWSLOGS_GROUP} awslogs-stream-prefix: lotto
  • 47. Metrics  Boot 2.0 ships with Micrometer integration  Metrics façade: SLF4J for metrics  Instruments many Spring components  Using this with Datadog
  • 48. Common Tags + Hystrix Metrics @Bean MeterRegistryCustomizer<MeterRegistry> commonTags(Environment env) { Region awsRegion = Regions.getCurrentRegion(); return registry -> registry.config().commonTags( "service", env.getProperty("spring.application.name), "environment", env.getProperty("environment", "local"), "version", env.getProperty("gw.version", "unknown-version"), "aws_region", awsRegion != null ? awsRegion.getName() : "-" ); } @Bean HystrixMetricsBinder hystrixMetricsBinder() { return new HystrixMetricsBinder(); }
  • 49. Think About Cardinality  Reduce possible values for metrics tags  HTTP metrics include URI @Bean MeterFilter queryParameterStrippingMeterFilter() { return MeterFilter.replaceTagValues("uri", url -> { int i = url.indexOf('?'); return i == -1 ? url : url.substring(0, i); }); }
  • 50. Conclusion  AWS Docker support less mature than expected  Lots of improvements all the time, though  Including Kubernetes support: EKS  Spring Cloud provides tons of great features  Central config, service discovery, tracing  Easy to add custom implementations
  • 51. THANKS! Q & A Joris Kuipers @jkuipers