Skip to content
v2.274.0

Experimental

@aws-cdk/aws-apprunner-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

Service L2 construct ​

The App Runner Service.

Example ​

ts
import * as iam from 'aws-cdk-lib/aws-iam';

const service = new apprunner.Service(this, 'Service', {
  source: apprunner.Source.fromEcrPublic({
    imageConfiguration: { port: 8000 },
    imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest',
  }),
});

service.addToRolePolicy(new iam.PolicyStatement({
  effect: iam.Effect.ALLOW,
  actions: ['s3:GetObject'],
  resources: ['*'],
}))
python
import aws_cdk.aws_iam as iam


service = apprunner.Service(self, "Service",
    source=apprunner.Source.from_ecr_public(
        image_configuration=apprunner.ImageConfiguration(port=8000),
        image_identifier="public.ecr.aws/aws-containers/hello-app-runner:latest"
    )
)

service.add_to_role_policy(iam.PolicyStatement(
    effect=iam.Effect.ALLOW,
    actions=["s3:GetObject"],
    resources=["*"]
))
java
import software.amazon.awscdk.services.iam.*;


Service service = Service.Builder.create(this, "Service")
        .source(Source.fromEcrPublic(EcrPublicProps.builder()
                .imageConfiguration(ImageConfiguration.builder().port(8000).build())
                .imageIdentifier("public.ecr.aws/aws-containers/hello-app-runner:latest")
                .build()))
        .build();

service.addToRolePolicy(PolicyStatement.Builder.create()
        .effect(Effect.ALLOW)
        .actions(List.of("s3:GetObject"))
        .resources(List.of("*"))
        .build());
csharp
// Install: dotnet add package Amazon.CDK.AWS.AppRunner.Alpha
using Amazon.CDK.AWS.IAM;


var service = new Service(this, "Service", new ServiceProps {
    Source = Source.FromEcrPublic(new EcrPublicProps {
        ImageConfiguration = new ImageConfiguration { Port = 8000 },
        ImageIdentifier = "public.ecr.aws/aws-containers/hello-app-runner:latest"
    })
});

service.AddToRolePolicy(new PolicyStatement(new PolicyStatementProps {
    Effect = Effect.ALLOW,
    Actions = new [] { "s3:GetObject" },
    Resources = new [] { "*" }
}));
go
// Install: go get github.com/aws/aws-cdk-go/awscdkapprunneralpha/v2
import "github.com/aws/aws-cdk-go/awscdk"


service := apprunner.NewService(this, jsii.String("Service"), &ServiceProps{
	Source: apprunner.Source_FromEcrPublic(&EcrPublicProps{
		ImageConfiguration: &ImageConfiguration{
			Port: jsii.Number(8000),
		},
		ImageIdentifier: jsii.String("public.ecr.aws/aws-containers/hello-app-runner:latest"),
	}),
})

service.AddToRolePolicy(iam.NewPolicyStatement(&PolicyStatementProps{
	Effect: iam.Effect_ALLOW,
	Actions: []*string{
		jsii.String("s3:GetObject"),
	},
	Resources: []*string{
		jsii.String("*"),
	},
}))

Initializer ​

ts
new Service(scope: Construct, id: string, props: ServiceProps)
python
Service(scope: Construct, id: str, props: ServiceProps)
java
new Service(Construct scope, String id, ServiceProps props)
csharp
new Service(Construct scope, string id, ServiceProps props)
go
NewService(Scope Construct, Id *string, Props ServiceProps)

Construct Props ​

accessRoleIRoleaccess_roleIRoleaccessRoleIRoleAccessRoleIRoleAccessRoleIRole= generate a new access role.#
The IAM role that grants the App Runner service access to a source repository.

It's required for ECR image repositories (but not for ECR Public repositories).

The role must be assumable by the 'build.apprunner.amazonaws.com' service principal.

autoDeploymentsEnabledbooleanauto_deployments_enabledboolautoDeploymentsEnabledBooleanAutoDeploymentsEnabledboolAutoDeploymentsEnabled*bool= no value will be passed.#
Specifies whether to enable continuous integration from the source repository.
notes

If true, continuous integration from the source repository is enabled for the App Runner service. Each repository change (including any source code commit or new image version) starts a deployment. By default, App Runner sets to false for a source image that uses an ECR Public repository or an ECR repository that's in an AWS account other than the one that the service is in. App Runner sets to true in all other cases (which currently include a source code repository or a source image using a same-account ECR repository).

autoScalingConfigurationIAutoScalingConfigurationauto_scaling_configurationIAutoScalingConfigurationautoScalingConfigurationIAutoScalingConfigurationAutoScalingConfigurationIAutoScalingConfigurationAutoScalingConfigurationIAutoScalingConfiguration= the latest revision of a default…#
Specifies an App Runner Auto Scaling Configuration.

A default configuration is either the AWS recommended configuration, or the configuration you set as the default.

default

Default: the latest revision of a default auto scaling configuration is used.

cpuCpucpuCpucpuCpuCpuCpuCpuCpu= Cpu.ONE_VCPU#
The number of CPU units reserved for each instance of your App Runner service.
healthCheckHealthCheckhealth_checkHealthCheckhealthCheckHealthCheckHealthCheckHealthCheckHealthCheckHealthCheck= no health check configuration#
Settings for the health check that AWS App Runner performs to monitor the health of a service.

You can specify it by static methods HealthCheck.http or HealthCheck.tcp.

instanceRoleIRoleinstance_roleIRoleinstanceRoleIRoleInstanceRoleIRoleInstanceRoleIRole= generate a new instance role.#
The IAM role that provides permissions to your App Runner service.

These are permissions that your code needs when it calls any AWS APIs.

The role must be assumable by the 'tasks.apprunner.amazonaws.com' service principal.

ipAddressTypeIpAddressTypeip_address_typeIpAddressTypeipAddressTypeIpAddressTypeIpAddressTypeIpAddressTypeIpAddressTypeIpAddressType= IpAddressType.IPV4#
The IP address type for your incoming public network configuration.
isPubliclyAccessiblebooleanis_publicly_accessibleboolisPubliclyAccessibleBooleanIsPubliclyAccessibleboolIsPubliclyAccessible*bool= true#
Specifies whether your App Runner service is publicly accessible.

If you use VpcIngressConnection, you must set this property to false.

kmsKeyIKeyRefkms_keyIKeyRefkmsKeyIKeyRefKmsKeyIKeyRefKmsKeyIKeyRef= Use an AWS managed key#
The customer managed key that AWS App Runner uses to encrypt copies of the source repository and service logs.
memoryMemorymemoryMemorymemoryMemoryMemoryMemoryMemoryMemory= Memory.TWO_GB#
The amount of memory reserved for each instance of your App Runner service.
observabilityConfigurationIObservabilityConfigurationobservability_configurationIObservabilityConfigurationobservabilityConfigurationIObservabilityConfigurationObservabilityConfigurationIObservabilityConfigurationObservabilityConfigurationIObservabilityConfiguration= no observability configuration r…#
Settings for an App Runner observability configuration.
default

Default: no observability configuration resource is associated with the service.

serviceNamestringservice_namestrserviceNameStringServiceNamestringServiceName*string= auto-generated if undefined.#
Name of the service.
sourceSourcesourceSourcesourceSourceSourceSourceSourceSourcerequired#
The source of the repository for the service.
vpcConnectorIVpcConnectorvpc_connectorIVpcConnectorvpcConnectorIVpcConnectorVpcConnectorIVpcConnectorVpcConnectorIVpcConnector= no VPC connector, uses the DEFAU…#
Settings for an App Runner VPC connector to associate with the service.
default

Default: no VPC connector, uses the DEFAULT egress type instead

Properties ​

The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

environment{ [key: string]: string }environmenttyping.Mapping[str, str]environmentMap<String, String>EnvironmentIDictionary<string, string>Environment*map[string]*stringrequireddeprecated#
use environmentVariables.
grantPrincipalIPrincipalgrant_principalIPrincipalgrantPrincipalIPrincipalGrantPrincipalIPrincipalGrantPrincipalIPrincipalrequired#
The principal to grant permissions to.
nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
serviceArnstringservice_arnstrserviceArnStringServiceArnstringServiceArn*stringrequired#
The ARN of the Service.
serviceIdstringservice_idstrserviceIdStringServiceIdstringServiceId*stringrequired#
The ID of the Service.
serviceNamestringservice_namestrserviceNameStringServiceNamestringServiceName*stringrequired#
The name of the service.
serviceStatusstringservice_statusstrserviceStatusStringServiceStatusstringServiceStatus*stringrequired#
The status of the Service.
serviceUrlstringservice_urlstrserviceUrlStringServiceUrlstringServiceUrl*stringrequired#
The URL of the Service.
stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.

Methods ​

addEnvironmentVariable(name: string, value: string): voiddef add_environment_variable(self, name: str, value: str) -> Nonepublic void addEnvironmentVariable(String name, String value)public void AddEnvironmentVariable(string name, string value)func AddEnvironmentVariable(Name *string, Value *string)#
This method adds an environment variable to the App Runner service.
addSecret(name: string, secret: Secret): voiddef add_secret(self, name: str, secret: Secret) -> Nonepublic void addSecret(String name, Secret secret)public void AddSecret(string name, Secret secret)func AddSecret(Name *string, Secret Secret)#
This method adds a secret as environment variable to the App Runner service.
addToRolePolicy(statement: PolicyStatement): voiddef add_to_role_policy(self, statement: PolicyStatement) -> Nonepublic void addToRolePolicy(PolicyStatement statement)public void AddToRolePolicy(PolicyStatement statement)func AddToRolePolicy(Statement PolicyStatement)#
Adds a statement to the instance role.
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

fromServiceAttributes(scope: Construct, id: string, attrs: ServiceAttributes): IService@staticmethod def from_service_attributes(scope: Construct, id: str, attrs: ServiceAttributes) -> IServicepublic static IService fromServiceAttributes(Construct scope, String id, ServiceAttributes attrs)public static IService FromServiceAttributes(Construct scope, string id, ServiceAttributes attrs)func FromServiceAttributes(Scope Construct, Id *string, Attrs ServiceAttributes) IServicestatic#
Import from service attributes.
fromServiceName(scope: Construct, id: string, serviceName: string): IService@staticmethod def from_service_name(scope: Construct, id: str, service_name: str) -> IServicepublic static IService fromServiceName(Construct scope, String id, String serviceName)public static IService FromServiceName(Construct scope, string id, string serviceName)func FromServiceName(Scope Construct, Id *string, ServiceName *string) IServicestatic#
Import from service name.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.