Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/@aws-cdk/aws-amplify-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ const amplifyApp = new amplify.App(this, 'MyApp', {
});
```

Also you can override the compute role for a specific branch by setting `computeRole` in `Branch`:

```ts
declare const computeRole: iam.Role;
declare const amplifyApp: amplify.App

const branch = amplifyApp.addBranch("dev", { computeRole });
```

## Cache Config

Amplify uses Amazon CloudFront to manage the caching configuration for your hosted applications. A cache configuration is applied to each app to optimize for the best performance.
Expand Down
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-amplify-alpha/lib/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ export interface BranchOptions {
* @default None - Default setting is no skew protection.
*/
readonly skewProtection?: boolean;

/**
* The IAM role to assign to a branch of an SSR app.
* The SSR Compute role allows the Amplify Hosting compute service to securely access specific AWS resources based on the role's permissions.
*
* This role overrides the app-level compute role.
*
* @default undefined - no specific role for the branch.
*/
readonly computeRole?: iam.IRole;
}

/**
Expand Down Expand Up @@ -199,6 +209,7 @@ export class Branch extends Resource implements IBranch {
stage: props.stage,
enablePerformanceMode: props.performanceMode,
enableSkewProtection: props.skewProtection,
computeRoleArn: props.computeRole?.roleArn,
});

this.arn = branch.attrArn;
Expand Down
19 changes: 19 additions & 0 deletions packages/@aws-cdk/aws-amplify-alpha/test/branch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Template } from 'aws-cdk-lib/assertions';
import { Asset } from 'aws-cdk-lib/aws-s3-assets';
import { SecretValue, Stack } from 'aws-cdk-lib';
import * as amplify from '../lib';
import * as iam from 'aws-cdk-lib/aws-iam';

let stack: Stack;
let app: amplify.App;
Expand Down Expand Up @@ -154,3 +155,21 @@ test('with skew protection', () => {
EnableSkewProtection: true,
});
});

test('with compute role', () => {
// WHEN
const computeRole = new iam.Role(stack, 'ComputeRole', {
assumedBy: new iam.ServicePrincipal('amplify.amazonaws.com'),
});

const ssrApp = new amplify.App(stack, 'SsrApp', {
platform: amplify.Platform.WEB_COMPUTE,
});

ssrApp.addBranch('main', { computeRole });

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Amplify::Branch', {
ComputeRoleArn: stack.resolve(computeRole.roleArn),
});
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"Resources": {
"ComputeRole65BDBE3E": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "amplify.amazonaws.com"
}
}
],
"Version": "2012-10-17"
}
}
},
"AppRole1AF9B530": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "amplify.amazonaws.com"
}
}
],
"Version": "2012-10-17"
}
}
},
"AppF1B96344": {
"Type": "AWS::Amplify::App",
"Properties": {
"BasicAuthConfig": {
"EnableBasicAuth": false
},
"CacheConfig": {
"Type": "AMPLIFY_MANAGED_NO_COOKIES"
},
"IAMServiceRole": {
"Fn::GetAtt": [
"AppRole1AF9B530",
"Arn"
]
},
"Name": "App",
"Platform": "WEB"
}
},
"AppmainF505BAED": {
"Type": "AWS::Amplify::Branch",
"Properties": {
"AppId": {
"Fn::GetAtt": [
"AppF1B96344",
"AppId"
]
},
"BranchName": "main",
"ComputeRoleArn": {
"Fn::GetAtt": [
"ComputeRole65BDBE3E",
"Arn"
]
},
"EnableAutoBuild": true,
"EnablePullRequestPreview": true
}
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading