/
application.ts
79 lines (70 loc) · 2.57 KB
/
application.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Construct, IResource, Resource } from '@aws-cdk/core';
import { CfnApplication } from "../codedeploy.generated";
import { arnForApplication } from "../utils";
/**
* Represents a reference to a CodeDeploy Application deploying to AWS Lambda.
*
* If you're managing the Application alongside the rest of your CDK resources,
* use the {@link LambdaApplication} class.
*
* If you want to reference an already existing Application,
* or one defined in a different CDK Stack,
* use the {@link LambdaApplication#fromLambdaApplicationName} method.
*/
export interface ILambdaApplication extends IResource {
/** @attribute */
readonly applicationArn: string;
/** @attribute */
readonly applicationName: string;
}
/**
* Construction properties for {@link LambdaApplication}.
*/
export interface LambdaApplicationProps {
/**
* The physical, human-readable name of the CodeDeploy Application.
*
* @default an auto-generated name will be used
*/
readonly applicationName?: string;
}
/**
* A CodeDeploy Application that deploys to an AWS Lambda function.
*
* @resource AWS::CodeDeploy::Application
*/
export class LambdaApplication extends Resource implements ILambdaApplication {
/**
* Import an Application defined either outside the CDK, or in a different CDK Stack.
*
* @param scope the parent Construct for this new Construct
* @param id the logical ID of this new Construct
* @param lambdaApplicationName the name of the application to import
* @returns a Construct representing a reference to an existing Application
*/
public static fromLambdaApplicationName(scope: Construct, id: string, lambdaApplicationName: string): ILambdaApplication {
class Import extends Resource implements ILambdaApplication {
public applicationArn = arnForApplication(lambdaApplicationName);
public applicationName = lambdaApplicationName;
}
return new Import(scope, id);
}
public readonly applicationArn: string;
public readonly applicationName: string;
constructor(scope: Construct, id: string, props: LambdaApplicationProps = {}) {
super(scope, id, {
physicalName: props.applicationName,
});
const resource = new CfnApplication(this, 'Resource', {
applicationName: this.physicalName,
computePlatform: 'Lambda'
});
this.applicationName = this.getResourceNameAttribute(resource.ref);
this.applicationArn = this.getResourceArnAttribute(arnForApplication(resource.ref), {
service: 'codedeploy',
resource: 'application',
resourceName: this.physicalName,
sep: ':',
});
}
}