> **Experimental**
>
> `@aws-cdk/aws-apprunner-alpha` is an [**experimental**](/stability) (alpha) package: its API may change in any release, without a major version bump.
# Service

The App Runner Service.

Extends: Construct › Resource › Service
Implements: IService, IResource, IGrantable, IEnvironmentAware, IConstruct, IDependable

- Stability: [Experimental](/cdk/api/stability.html)
- Source: [`lib/service.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0-alpha.0/packages/@aws-cdk/aws-apprunner-alpha/lib/service.ts#L1191)

## 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: ['*'],
}))
```

## Initializer

```ts
new Service(scope: Construct, id: string, props: ServiceProps)
```

## Construct Props

- `accessRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The IAM role that grants the App Runner service access to a source repository.

  **Default:** generate a new access role.

  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.

- `autoDeploymentsEnabled`: boolean — Specifies whether to enable continuous integration from the source repository.

  **Default:** no value will be passed.

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

- `autoScalingConfiguration`: [IAutoScalingConfiguration](/cdk/api/v2/docs/@aws-cdk_aws-apprunner-alpha.IAutoScalingConfiguration.html) — Specifies an App Runner Auto Scaling Configuration.

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

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

- `cpu`: [Cpu](/cdk/api/v2/docs/@aws-cdk_aws-apprunner-alpha.Cpu.html) = Cpu.ONE_VCPU — The number of CPU units reserved for each instance of your App Runner service.

- `healthCheck`: [HealthCheck](/cdk/api/v2/docs/@aws-cdk_aws-apprunner-alpha.HealthCheck.html) — Settings for the health check that AWS App Runner performs to monitor the health of a service.

  **Default:** no health check configuration

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

- `instanceRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The IAM role that provides permissions to your App Runner service.

  **Default:** generate a new instance role.

  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.

- `ipAddressType`: [IpAddressType](/cdk/api/v2/docs/@aws-cdk_aws-apprunner-alpha.IpAddressType.html) = IpAddressType.IPV4 — The IP address type for your incoming public network configuration.

- `isPubliclyAccessible`: boolean = true — Specifies whether your App Runner service is publicly accessible.

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

- `kmsKey`: [IKeyRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_kms.IKeyRef.html) — The customer managed key that AWS App Runner uses to encrypt copies of the source repository and service logs.

  **Default:** Use an AWS managed key

- `memory`: [Memory](/cdk/api/v2/docs/@aws-cdk_aws-apprunner-alpha.Memory.html) = Memory.TWO_GB — The amount of memory reserved for each instance of your App Runner service.

- `observabilityConfiguration`: [IObservabilityConfiguration](/cdk/api/v2/docs/@aws-cdk_aws-apprunner-alpha.IObservabilityConfiguration.html) — Settings for an App Runner observability configuration.

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

- `serviceName`: string — Name of the service.

  **Default:** auto-generated if undefined.

- `source`: [Source](/cdk/api/v2/docs/@aws-cdk_aws-apprunner-alpha.Source.html) (required) — The source of the repository for the service.

- `vpcConnector`: [IVpcConnector](/cdk/api/v2/docs/@aws-cdk_aws-apprunner-alpha.IVpcConnector.html) — Settings for an App Runner VPC connector to associate with the service.

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

## Properties

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) (required) — The environment this resource belongs to.

  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 } (required) — use environmentVariables.

- `grantPrincipal`: [IPrincipal](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IPrincipal.html) (required) — The principal to grant permissions to.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) (required) — The tree node.

- `PROPERTY_INJECTION_ID`: string (required) (static) — Uniquely identifies this class.

- `serviceArn`: string (required) — The ARN of the Service.

- `serviceId`: string (required) — The ID of the Service.

- `serviceName`: string (required) — The name of the service.

- `serviceStatus`: string (required) — The status of the Service.

- `serviceUrl`: string (required) — The URL of the Service.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) (required) — The stack in which this resource is defined.

## Methods

- `addEnvironmentVariable(name: string, value: string): void` — This method adds an environment variable to the App Runner service.

- `addSecret(name: string, secret: Secret): void` — This method adds a secret as environment variable to the App Runner service.

- `addToRolePolicy(statement: PolicyStatement): void` — Adds a statement to the instance role.

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  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**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — 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`).

- `fromServiceAttributes(scope: Construct, id: string, attrs: ServiceAttributes): IService` (static) — Import from service attributes.

- `fromServiceName(scope: Construct, id: string, serviceName: string): IService` (static) — Import from service name.

- `isConstruct(x: any): boolean` (static) — 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 object.

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

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `toString(): string` — Returns a string representation of this construct.

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