Skip to content

Commit 4dbae36

Browse files
committed
add ObservabilityConfiguration for AppRunner Service
1 parent ccbd99f commit 4dbae36

15 files changed

+866
-4
lines changed

packages/@aws-cdk/aws-apprunner-alpha/README.md

+21-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The `Service` construct allows you to create AWS App Runner services with `ECR P
3232
- `Source.fromEcr()` - To define the source repository from `ECR`.
3333
- `Source.fromEcrPublic()` - To define the source repository from `ECR Public`.
3434
- `Source.fromGitHub()` - To define the source repository from the `Github repository`.
35-
- `Source.fromAsset()` - To define the source from local asset directory.
35+
- `Source.fromAsset()` - To define the source from local asset directory.
3636

3737

3838
The `Service` construct implements `IGrantable`.
@@ -183,7 +183,7 @@ new apprunner.Service(this, 'Service', {
183183
## Secrets Manager
184184

185185
To include environment variables integrated with AWS Secrets Manager, use the `environmentSecrets` attribute.
186-
You can use the `addSecret` method from the App Runner `Service` class to include secrets from outside the
186+
You can use the `addSecret` method from the App Runner `Service` class to include secrets from outside the
187187
service definition.
188188

189189
```ts
@@ -237,3 +237,22 @@ new apprunner.Service(this, 'Service', {
237237
}),
238238
});
239239
```
240+
241+
## Observability Configuration
242+
243+
To associate an App Runner service with a custom Observability Configuration, define `observabilityConfiguration` for the service.
244+
245+
```ts
246+
const observabilityConfiguration = new ObservabilityConfiguration(stack, 'ObservabilityConfiguration', {
247+
observabilityConfigurationName: 'MyObservabilityConfiguration',
248+
vendor: Vendor.AWSXRAY,
249+
});
250+
251+
new apprunner.Service(this, 'DemoService', {
252+
source: apprunner.Source.fromEcrPublic({
253+
imageConfiguration: { port: 8000 },
254+
imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest',
255+
}),
256+
observabilityConfiguration,
257+
});
258+
```
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
// AWS::AppRunner CloudFormation Resources:
22
export * from './service';
33
export * from './vpc-connector';
4+
export * from './observability-configuration';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import * as cdk from 'aws-cdk-lib/core';
2+
import { Construct } from 'constructs';
3+
import { CfnObservabilityConfiguration } from 'aws-cdk-lib/aws-apprunner';
4+
5+
/**
6+
* The implementation provider chosen for tracing App Runner services
7+
*/
8+
export enum Vendor {
9+
/**
10+
* AWS X-RAY
11+
*/
12+
AWSXRAY = 'AWSXRAY',
13+
}
14+
15+
/**
16+
* Properties of the AppRunner Observability configuration
17+
*/
18+
export interface ObservabilityConfigurationProps {
19+
/**
20+
* The name for the ObservabilityConfiguration.
21+
*
22+
* @default - a name generated by CloudFormation
23+
*/
24+
readonly observabilityConfigurationName?: string;
25+
26+
/**
27+
* The implementation provider chosen for tracing App Runner services.
28+
*
29+
* @default Vendor.AWSXRAY
30+
*/
31+
readonly vendor?: Vendor;
32+
}
33+
34+
/**
35+
* Attributes for the App Runner Observability configuration
36+
*/
37+
export interface ObservabilityConfigurationAttributes {
38+
/**
39+
* The name of the Observability configuration.
40+
*/
41+
readonly observabilityConfigurationName: string;
42+
43+
/**
44+
* The ARN of the Observability configuration.
45+
*/
46+
readonly observabilityConfigurationArn: string;
47+
48+
/**
49+
* The revision of the Observability configuration.
50+
*/
51+
readonly observabilityConfigurationRevision: number;
52+
}
53+
54+
/**
55+
* Represents the App Runner Observability configuration.
56+
*/
57+
export interface IObservabilityConfiguration extends cdk.IResource {
58+
/**
59+
* The Name of the Observability configuration.
60+
* @attribute
61+
*/
62+
readonly observabilityConfigurationName: string;
63+
64+
/**
65+
* The ARN of the Observability configuration.
66+
* @attribute
67+
*/
68+
readonly observabilityConfigurationArn: string;
69+
70+
/**
71+
* The revision of the Observability configuration.
72+
* @attribute
73+
*/
74+
readonly observabilityConfigurationRevision: number;
75+
}
76+
77+
/**
78+
* The App Runner Observability configuration
79+
*
80+
* @resource AWS::AppRunner::ObservabilityConfiguration
81+
*/
82+
export class ObservabilityConfiguration extends cdk.Resource implements IObservabilityConfiguration {
83+
/**
84+
* Import from Observability configuration attributes.
85+
*/
86+
public static fromObservabilityConfigurationAttributes(scope: Construct, id: string,
87+
attrs: ObservabilityConfigurationAttributes): IObservabilityConfiguration {
88+
const observabilityConfigurationArn = attrs.observabilityConfigurationArn;
89+
const observabilityConfigurationName = attrs.observabilityConfigurationName;
90+
const observabilityConfigurationRevision = attrs.observabilityConfigurationRevision;
91+
92+
class Import extends cdk.Resource {
93+
public readonly observabilityConfigurationArn = observabilityConfigurationArn
94+
public readonly observabilityConfigurationName = observabilityConfigurationName
95+
public readonly observabilityConfigurationRevision = observabilityConfigurationRevision
96+
}
97+
98+
return new Import(scope, id);
99+
}
100+
101+
/**
102+
* The ARN of the Observability configuration.
103+
* @attribute
104+
*/
105+
readonly observabilityConfigurationArn: string;
106+
107+
/**
108+
* The revision of the Observability configuration.
109+
* @attribute
110+
*/
111+
readonly observabilityConfigurationRevision: number;
112+
113+
/**
114+
* The name of the Observability configuration.
115+
* @attribute
116+
*/
117+
readonly observabilityConfigurationName: string;
118+
119+
public constructor(scope: Construct, id: string, props: ObservabilityConfigurationProps = {}) {
120+
super(scope, id, {
121+
physicalName: props.observabilityConfigurationName,
122+
});
123+
124+
const resource = new CfnObservabilityConfiguration(this, 'Resource', {
125+
observabilityConfigurationName: props.observabilityConfigurationName,
126+
traceConfiguration: {
127+
vendor: props.vendor ?? Vendor.AWSXRAY,
128+
},
129+
});
130+
131+
this.observabilityConfigurationArn = resource.attrObservabilityConfigurationArn;
132+
this.observabilityConfigurationRevision = resource.attrObservabilityConfigurationRevision;
133+
this.observabilityConfigurationName = resource.ref;
134+
}
135+
}

packages/@aws-cdk/aws-apprunner-alpha/lib/service.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Lazy } from 'aws-cdk-lib/core';
88
import { Construct } from 'constructs';
99
import { CfnService } from 'aws-cdk-lib/aws-apprunner';
1010
import { IVpcConnector } from './vpc-connector';
11+
import { IObservabilityConfiguration } from './observability-configuration';
1112

1213
/**
1314
* The image repository types
@@ -79,7 +80,7 @@ export class Cpu {
7980
*
8081
* @param unit The unit of CPU.
8182
*/
82-
private constructor(public readonly unit: string) {}
83+
private constructor(public readonly unit: string) { }
8384
}
8485

8586
/**
@@ -715,6 +716,13 @@ export interface ServiceProps {
715716
* @default - no health check configuration
716717
*/
717718
readonly healthCheck?: HealthCheck;
719+
720+
/**
721+
* Settings for an App Runner tracing feature.
722+
*
723+
* @default - Not enable tracing
724+
*/
725+
readonly observabilityConfiguration?: IObservabilityConfiguration;
718726
}
719727

720728
/**
@@ -1248,6 +1256,10 @@ export class Service extends cdk.Resource implements iam.IGrantable {
12481256
healthCheckConfiguration: this.props.healthCheck ?
12491257
this.props.healthCheck.bind() :
12501258
undefined,
1259+
observabilityConfiguration: props.observabilityConfiguration ? {
1260+
observabilityEnabled: true,
1261+
observabilityConfigurationArn: props.observabilityConfiguration?.observabilityConfigurationArn,
1262+
} : undefined,
12511263
});
12521264

12531265
// grant required privileges for the role

packages/@aws-cdk/aws-apprunner-alpha/test/integ.service-observability-configuration.js.snapshot/AppRunnerObservabilityConfigurationDefaultTestDeployAssertFEB7E279.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-apprunner-alpha/test/integ.service-observability-configuration.js.snapshot/AppRunnerObservabilityConfigurationDefaultTestDeployAssertFEB7E279.template.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-apprunner-alpha/test/integ.service-observability-configuration.js.snapshot/cdk.out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-apprunner-alpha/test/integ.service-observability-configuration.js.snapshot/integ-apprunner-observability-configuration.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)