Service

class aws_cdk.aws_apprunner_alpha.Service(scope, id, *, source, access_role=None, auto_deployments_enabled=None, cpu=None, health_check=None, instance_role=None, memory=None, service_name=None, vpc_connector=None)

Bases: Resource

(experimental) The App Runner Service.

Stability:

experimental

ExampleMetadata:

infused

Example:

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=["*"]
))
Parameters:
  • scope (Construct) –

  • id (str) –

  • source (Source) – (experimental) The source of the repository for the service.

  • access_role (Optional[IRole]) – (experimental) 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. Default: - generate a new access role.

  • auto_deployments_enabled (Optional[bool]) – (experimental) Specifies whether to enable continuous integration from the source repository. 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). Default: - no value will be passed.

  • cpu (Optional[Cpu]) – (experimental) The number of CPU units reserved for each instance of your App Runner service. Default: Cpu.ONE_VCPU

  • health_check (Optional[HealthCheck]) – (experimental) 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. Default: - no health check configuration

  • instance_role (Optional[IRole]) – (experimental) 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. Default: - generate a new instance role.

  • memory (Optional[Memory]) – (experimental) The amount of memory reserved for each instance of your App Runner service. Default: Memory.TWO_GB

  • service_name (Optional[str]) – (experimental) Name of the service. Default: - auto-generated if undefined.

  • vpc_connector (Optional[IVpcConnector]) – (experimental) Settings for an App Runner VPC connector to associate with the service. Default: - no VPC connector, uses the DEFAULT egress type instead

Stability:

experimental

Methods

add_environment_variable(name, value)

(experimental) This method adds an environment variable to the App Runner service.

Parameters:
  • name (str) –

  • value (str) –

Stability:

experimental

Return type:

None

add_secret(name, secret)

(experimental) This method adds a secret as environment variable to the App Runner service.

Parameters:
  • name (str) –

  • secret (Secret) –

Stability:

experimental

Return type:

None

add_to_role_policy(statement)

(experimental) Adds a statement to the instance role.

Parameters:

statement (PolicyStatement) –

Stability:

experimental

Return type:

None

apply_removal_policy(policy)

Apply the given removal policy to this resource.

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).

Parameters:

policy (RemovalPolicy) –

Return type:

None

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

env

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.

environment

(deprecated) Environment variables for this service.

Deprecated:

use environmentVariables.

Stability:

deprecated

grant_principal

(experimental) The principal to grant permissions to.

Stability:

experimental

node

The tree node.

service_arn

(experimental) The ARN of the Service.

Stability:

experimental

Attribute:

true

service_id

(experimental) The ID of the Service.

Stability:

experimental

Attribute:

true

service_name

(experimental) The name of the service.

Stability:

experimental

service_status

(experimental) The status of the Service.

Stability:

experimental

Attribute:

true

service_url

(experimental) The URL of the Service.

Stability:

experimental

Attribute:

true

stack

The stack in which this resource is defined.

Static Methods

classmethod from_service_attributes(scope, id, *, service_arn, service_name, service_status, service_url)

(experimental) Import from service attributes.

Parameters:
  • scope (Construct) –

  • id (str) –

  • service_arn (str) – (experimental) The ARN of the service.

  • service_name (str) – (experimental) The name of the service.

  • service_status (str) – (experimental) The status of the service.

  • service_url (str) – (experimental) The URL of the service.

Stability:

experimental

Return type:

IService

classmethod from_service_name(scope, id, service_name)

(experimental) Import from service name.

Parameters:
  • scope (Construct) –

  • id (str) –

  • service_name (str) –

Stability:

experimental

Return type:

IService

classmethod is_construct(x)

Checks if x is a construct.

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:

x (Any) – Any object.

Return type:

bool

Returns:

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

classmethod is_owned_resource(construct)

Returns true if the construct was created by CDK, and false otherwise.

Parameters:

construct (IConstruct) –

Return type:

bool

classmethod is_resource(construct)

Check whether the given construct is a Resource.

Parameters:

construct (IConstruct) –

Return type:

bool