Skip to content

Instantly share code, notes, and snippets.

View axelhodler's full-sized avatar

Axel Hodler axelhodler

View GitHub Profile
testfargateLBPublicListenerECSGroup81318DEB:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckPath: /actuator/health
Port: 80
Protocol: HTTP
TargetType: ip
VpcId:
Ref: EcsDefaultClusterMnL3mNNYNVpc7788A521
Metadata:
testfargateLBPublicListenerECSGroup81318DEB:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Port: 80
Protocol: HTTP
TargetType: ip
VpcId:
Ref: EcsDefaultClusterMnL3mNNYNVpc7788A521
Metadata:
aws:cdk:path: CdktestsStack/test-fargate/LB/PublicListener/ECSGroup/Resource
const albfs = new ApplicationLoadBalancedFargateService(this, 'test-fargate', {
taskImageOptions: {
image: ecs.ContainerImage.fromEcrRepository(repository, 'latest')
}
})
albfs.targetGroup.configureHealthCheck({
path: '/actuator/health',
});
test('ELB health check path is using Spring Boot endpoint', () => {
const app = new cdk.App();
const stack = new Cdktests.CdktestsStack(app, 'MyTestStack');
expectCDK(stack).to(haveResource("AWS::ElasticLoadBalancingV2::TargetGroup",{
HealthCheckPath: '/actuator/health'
}));
});
@axelhodler
axelhodler / cdktests-stack.ts
Created February 23, 2021 16:22
Adding ApplicationLoadBalancedFargateService
import * as cdk from '@aws-cdk/core';
import * as ecr from '@aws-cdk/aws-ecr';
import * as ecs from '@aws-cdk/aws-ecs';
import {ApplicationLoadBalancedFargateService} from "@aws-cdk/aws-ecs-patterns";
export class CdktestsStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const repository = new ecr.Repository(this, 'test-repository', {
@axelhodler
axelhodler / cdktests.test.ts
Created February 23, 2021 16:07
Test containerdefinition image
test('Fargate is using the latest image in ECR', () => {
const app = new cdk.App();
const stack = new Cdktests.CdktestsStack(app, 'MyTestStack');
expectCDK(stack).to(haveResourceLike("AWS::ECS::TaskDefinition",{
ContainerDefinitions: [{
Image: {
"Fn::Join": [
"",
test('Fargate service is using the default values', () => {
const app = new cdk.App();
const stack = new Cdktests.CdktestsStack(app, 'MyTestStack');
expectCDK(stack).to(haveResource("AWS::ECS::Service",{
LaunchType: 'FARGATE',
DesiredCount: 1,
HealthCheckGracePeriodSeconds: 60
}));
@axelhodler
axelhodler / cdktests.test.ts
Last active February 28, 2021 14:18
ECR Test
import { expect as expectCDK, haveResource } from '@aws-cdk/assert';
import * as cdk from '@aws-cdk/core';
import * as Cdktests from '../lib/cdktests-stack';
test('ECR Resource is present', () => {
const app = new cdk.App();
const stack = new Cdktests.CdktestsStack(app, 'MyTestStack');
expectCDK(stack).to(haveResource("AWS::ECR::Repository",{
@axelhodler
axelhodler / withrepository.yaml
Created February 21, 2021 14:00
CloudFormation stack after adding repository
Resources:
testrepository3CFC24EC:
Type: AWS::ECR::Repository
Properties:
RepositoryName: test
UpdateReplacePolicy: Retain
DeletionPolicy: Retain
Metadata:
aws:cdk:path: CdktestsStack/test-repository/Resource
CDKMetadata:
@axelhodler
axelhodler / cdktests-stack.ts
Created February 21, 2021 09:32
Adding ECR
import * as cdk from '@aws-cdk/core';
import * as ecr from '@aws-cdk/aws-ecr';
export class CdktestsStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new ecr.Repository(this, 'test-repository', {
repositoryName: `test`
});