Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(elb): set accessLoggingPolicy property with L2 LoadBalancer #14983

Merged
merged 12 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ export interface LoadBalancerProps {
* @default - Public subnets if internetFacing, Private subnets otherwise
*/
readonly subnetSelection?: SubnetSelection;

/**
* Enable Loadbalancer access logs
* Can be used to avoid manual work as aws console
* Required S3 bucket name , enabled flag
* Can add interval for pushing log
* Can set bucket prefix in order to provide folder name inside bucket
* @default - disabled
*/
readonly accessLoggingPolicy?: CfnLoadBalancer.AccessLoggingPolicyProperty;

}

/**
Expand Down Expand Up @@ -262,6 +273,10 @@ export class LoadBalancer extends Resource implements IConnectable {
this.elb.node.addDependency(selectedSubnets.internetConnectivityEstablished);
}

if (props.accessLoggingPolicy !== undefined) {
this.elb.accessLoggingPolicy = props.accessLoggingPolicy;
}

ifUndefined(props.listeners, []).forEach(b => this.addListener(b));
ifUndefined(props.targets, []).forEach(t => this.addTarget(t));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,52 @@ describe('tests', () => {
sslCertificateId: sslCertificateArn,
})).toThrow(/"sslCertificateId" is deprecated, please use "sslCertificateArn" only./);
});

test('enable load balancer access logs', () => {
// GIVEN
const stack = new Stack();
const vpc = new Vpc(stack, 'VCP');

// WHEN
new LoadBalancer(stack, 'LB', {
vpc,
accessLoggingPolicy: {
enabled: true,
s3BucketName: 'fakeBucket',
},
});

// THEN
expect(stack).toHaveResource('AWS::ElasticLoadBalancing::LoadBalancer', {
AccessLoggingPolicy: {
Enabled: true,
S3BucketName: 'fakeBucket',
},
});
});

test('disable load balancer access logs', () => {
// GIVEN
const stack = new Stack();
const vpc = new Vpc(stack, 'VCP');

// WHEN
new LoadBalancer(stack, 'LB', {
vpc,
accessLoggingPolicy: {
enabled: false,
s3BucketName: 'fakeBucket',
},
});

// THEN
expect(stack).toHaveResource('AWS::ElasticLoadBalancing::LoadBalancer', {
AccessLoggingPolicy: {
Enabled: false,
S3BucketName: 'fakeBucket',
},
});
});
});

class FakeTarget implements ILoadBalancerTarget {
Expand Down