23
23
24
24
This module is part of the [ AWS Cloud Development Kit] ( https://github.com/aws/aws-cdk ) project.
25
25
26
- ``` ts
27
- import apprunner = require ( ' @aws-cdk/aws-apprunner' ) ;
26
+ ``` ts nofixture
27
+ import * as apprunner from ' @aws-cdk/aws-apprunner' ;
28
28
```
29
29
30
30
## Introduction
@@ -46,8 +46,8 @@ The `Service` construct allows you to create AWS App Runner services with `ECR P
46
46
To create a ` Service ` with ECR Public:
47
47
48
48
``` ts
49
- new Service (stack , ' Service' , {
50
- source: Source .fromEcrPublic ({
49
+ new apprunner . Service (this , ' Service' , {
50
+ source: apprunner . Source .fromEcrPublic ({
51
51
imageConfiguration: { port: 8000 },
52
52
imageIdentifier: ' public.ecr.aws/aws-containers/hello-app-runner:latest' ,
53
53
}),
@@ -59,10 +59,12 @@ new Service(stack, 'Service', {
59
59
To create a ` Service ` from an existing ECR repository:
60
60
61
61
``` ts
62
- new Service (stack , ' Service' , {
63
- source: Source .fromEcr ({
62
+ import * as ecr from ' @aws-cdk/aws-ecr' ;
63
+
64
+ new apprunner .Service (this , ' Service' , {
65
+ source: apprunner .Source .fromEcr ({
64
66
imageConfiguration: { port: 80 },
65
- repository: ecr .Repository .fromRepositoryName (stack , ' NginxRepository' , ' nginx' ),
67
+ repository: ecr .Repository .fromRepositoryName (this , ' NginxRepository' , ' nginx' ),
66
68
tag: ' latest' ,
67
69
}),
68
70
});
@@ -71,11 +73,13 @@ new Service(stack, 'Service', {
71
73
To create a ` Service ` from local docker image asset directory built and pushed to Amazon ECR:
72
74
73
75
``` ts
74
- const imageAsset = new assets .DockerImageAsset (stack , ' ImageAssets' , {
76
+ import * as assets from ' @aws-cdk/aws-ecr-assets' ;
77
+
78
+ const imageAsset = new assets .DockerImageAsset (this , ' ImageAssets' , {
75
79
directory: path .join (__dirname , ' ./docker.assets' ),
76
80
});
77
- new Service (stack , ' Service' , {
78
- source: Source .fromAsset ({
81
+ new apprunner . Service (this , ' Service' , {
82
+ source: apprunner . Source .fromAsset ({
79
83
imageConfiguration: { port: 8000 },
80
84
asset: imageAsset ,
81
85
}),
@@ -89,36 +93,35 @@ To create a `Service` from the GitHub repository, you need to specify an existin
89
93
See [ Managing App Runner connections] ( https://docs.aws.amazon.com/apprunner/latest/dg/manage-connections.html ) for more details.
90
94
91
95
``` ts
92
- new Service (stack , ' Service' , {
93
- source: Source .fromGitHub ({
96
+ new apprunner . Service (this , ' Service' , {
97
+ source: apprunner . Source .fromGitHub ({
94
98
repositoryUrl: ' https://github.com/aws-containers/hello-app-runner' ,
95
99
branch: ' main' ,
96
- configurationSource: ConfigurationSourceType .REPOSITORY ,
97
- connection: GitHubConnection .fromConnectionArn (' CONNECTION_ARN' ),
100
+ configurationSource: apprunner . ConfigurationSourceType .REPOSITORY ,
101
+ connection: apprunner . GitHubConnection .fromConnectionArn (' CONNECTION_ARN' ),
98
102
}),
99
103
});
100
104
```
101
105
102
106
Use ` codeConfigurationValues ` to override configuration values with the ` API ` configuration source type.
103
107
104
108
``` ts
105
- new Service (stack , ' Service' , {
106
- source: Source .fromGitHub ({
109
+ new apprunner . Service (this , ' Service' , {
110
+ source: apprunner . Source .fromGitHub ({
107
111
repositoryUrl: ' https://github.com/aws-containers/hello-app-runner' ,
108
112
branch: ' main' ,
109
- configurationSource: ConfigurationSourceType .API ,
113
+ configurationSource: apprunner . ConfigurationSourceType .API ,
110
114
codeConfigurationValues: {
111
- runtime: Runtime .PYTHON_3 ,
115
+ runtime: apprunner . Runtime .PYTHON_3 ,
112
116
port: ' 8000' ,
113
117
startCommand: ' python app.py' ,
114
118
buildCommand: ' yum install -y pycairo && pip install -r requirements.txt' ,
115
119
},
116
- connection: GitHubConnection .fromConnectionArn (' CONNECTION_ARN' ),
120
+ connection: apprunner . GitHubConnection .fromConnectionArn (' CONNECTION_ARN' ),
117
121
}),
118
122
});
119
123
```
120
124
121
-
122
125
## IAM Roles
123
126
124
127
You are allowed to define ` instanceRole ` and ` accessRole ` for the ` Service ` .
0 commit comments