Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions doc/custom-domain.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ For example, if you want to use blue/green deployments, you might need to associ

For more information about managing domains with the CLI, see the [Commands](commands.md#domain) section.

⚠️ The CLI commands resolve values themselves rather than through CloudFormation, so `certificateArn` must be a literal ARN string when using them. CloudFormation intrinsic functions (e.g. `Fn::ImportValue`) are only resolved when the domain is managed by CloudFormation (`useCloudFormation: true`).

## Ejecting from CloudFormation

If you started to manage your domain through CloudFormation and want to eject from it, follow the following steps:
Expand Down
26 changes: 26 additions & 0 deletions src/__tests__/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

expect(createCall).toBeDefined();
expect(listCertCall).toBeUndefined();
expect(createCall![0].input).toMatchInlineSnapshot(`

Check warning on line 88 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (26)

Forbidden non-null assertion

Check warning on line 88 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (20)

Forbidden non-null assertion

Check warning on line 88 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (22)

Forbidden non-null assertion

Check warning on line 88 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (24)

Forbidden non-null assertion
{
"certificateArn": "arn:aws:acm:us-east-1:123456789012:certificate/8acd9c69-1704-462c-be91-b5d7ce45c493",
"domainName": "api.example.com",
Expand All @@ -93,6 +93,32 @@
`);
});

it('should reject an intrinsic-function certificateArn (CLI cannot resolve it)', async () => {
mockSend.mockResolvedValue({});

await expect(
runServerless({
fixture: 'appsync',
command: 'appsync domain create',
configExt: {
appSync: {
domain: {
useCloudFormation: false,
certificateArn: { 'Fn::ImportValue': 'exportedCertArn' },
},
},
},
}),
).rejects.toThrow(
/the `appsync domain` CLI commands require a plain ARN string/,
);

const createCall = mockSend.mock.calls.find(
([cmd]) => cmd instanceof CreateDomainNameCommand,
);
expect(createCall).toBeUndefined();
});

it('should create a domain and find a matching certificate, exact match', async () => {
mockSend.mockImplementation((cmd) => {
if (cmd instanceof ListCertificatesCommand) {
Expand Down Expand Up @@ -147,7 +173,7 @@
}
`);
expect(createCall).toBeDefined();
expect(createCall![0].input).toMatchInlineSnapshot(`

Check warning on line 176 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (26)

Forbidden non-null assertion

Check warning on line 176 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (20)

Forbidden non-null assertion

Check warning on line 176 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (22)

Forbidden non-null assertion

Check warning on line 176 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (24)

Forbidden non-null assertion
{
"certificateArn": "arn:aws:acm:us-east-1:123456789012:certificate/8acd9c69-1704-462c-be91-b5d7ce45c493",
"domainName": "api.example.com",
Expand Down Expand Up @@ -254,7 +280,7 @@
}
`);
expect(createCall).toBeDefined();
expect(createCall![0].input).toMatchInlineSnapshot(`

Check warning on line 283 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (26)

Forbidden non-null assertion

Check warning on line 283 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (20)

Forbidden non-null assertion

Check warning on line 283 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (22)

Forbidden non-null assertion

Check warning on line 283 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (24)

Forbidden non-null assertion
{
"certificateArn": "arn:aws:acm:us-east-1:123456789012:certificate/fd8f67f7-bf19-4894-80db-0c49bf5dd507",
"domainName": "api.example.com",
Expand Down Expand Up @@ -284,7 +310,7 @@
([cmd]) => cmd instanceof DeleteDomainNameCommand,
);
expect(deleteCall).toBeDefined();
expect(deleteCall![0].input).toMatchInlineSnapshot(`

Check warning on line 313 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (26)

Forbidden non-null assertion

Check warning on line 313 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (20)

Forbidden non-null assertion

Check warning on line 313 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (22)

Forbidden non-null assertion

Check warning on line 313 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (24)

Forbidden non-null assertion
{
"domainName": "api.example.com",
}
Expand Down Expand Up @@ -316,7 +342,7 @@
([cmd]) => cmd instanceof DeleteDomainNameCommand,
);
expect(deleteCall).toBeDefined();
expect(deleteCall![0].input).toMatchInlineSnapshot(`

Check warning on line 345 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (26)

Forbidden non-null assertion

Check warning on line 345 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (20)

Forbidden non-null assertion

Check warning on line 345 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (22)

Forbidden non-null assertion

Check warning on line 345 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (24)

Forbidden non-null assertion
{
"domainName": "api.example.com",
}
Expand Down Expand Up @@ -396,7 +422,7 @@
},
]
`);
expect(associateCall![0].input).toMatchInlineSnapshot(`

Check warning on line 425 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (26)

Forbidden non-null assertion

Check warning on line 425 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (20)

Forbidden non-null assertion

Check warning on line 425 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (22)

Forbidden non-null assertion

Check warning on line 425 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (24)

Forbidden non-null assertion
{
"apiId": "123456789",
"domainName": "api.example.com",
Expand Down Expand Up @@ -494,7 +520,7 @@
},
]
`);
expect(associateCall![0].input).toMatchInlineSnapshot(`

Check warning on line 523 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (26)

Forbidden non-null assertion

Check warning on line 523 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (20)

Forbidden non-null assertion

Check warning on line 523 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (22)

Forbidden non-null assertion

Check warning on line 523 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (24)

Forbidden non-null assertion
{
"apiId": "123456789",
"domainName": "api.example.com",
Expand Down Expand Up @@ -554,7 +580,7 @@
},
]
`);
expect(associateCall![0].input).toMatchInlineSnapshot(`

Check warning on line 583 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (26)

Forbidden non-null assertion

Check warning on line 583 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (20)

Forbidden non-null assertion

Check warning on line 583 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (22)

Forbidden non-null assertion

Check warning on line 583 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (24)

Forbidden non-null assertion
{
"apiId": "123456789",
"domainName": "api.example.com",
Expand Down Expand Up @@ -613,7 +639,7 @@
},
]
`);
expect(disassocCall![0].input).toMatchInlineSnapshot(`

Check warning on line 642 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (26)

Forbidden non-null assertion

Check warning on line 642 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (20)

Forbidden non-null assertion

Check warning on line 642 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (22)

Forbidden non-null assertion

Check warning on line 642 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (24)

Forbidden non-null assertion
{
"domainName": "api.example.com",
}
Expand Down Expand Up @@ -672,7 +698,7 @@
},
]
`);
expect(disassocCall![0].input).toMatchInlineSnapshot(`

Check warning on line 701 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (26)

Forbidden non-null assertion

Check warning on line 701 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (20)

Forbidden non-null assertion

Check warning on line 701 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (22)

Forbidden non-null assertion

Check warning on line 701 in src/__tests__/commands.test.ts

View workflow job for this annotation

GitHub Actions / tests (24)

Forbidden non-null assertion
{
"domainName": "api.example.com",
}
Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,14 @@ class ServerlessAppsyncPlugin {
);
}

if (typeof certificateArn !== 'string') {
throw new this.serverless.classes.Error(
`Invalid \`certificateArn\`: the \`appsync domain\` CLI commands require a plain ARN string. ` +
`CloudFormation intrinsic functions (e.g. Fn::ImportValue) can only be resolved by CloudFormation, not by the CLI. ` +
`Either pass a literal ARN, or manage the domain through CloudFormation (the default, \`domain.useCloudFormation: true\`), where the intrinsic function will be resolved.`,
);
}

await this.clientFactory.getAppSyncClient().send(
new CreateDomainNameCommand({
domainName: domain.name,
Expand Down
2 changes: 1 addition & 1 deletion src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export type DomainConfig = {
useCloudFormation?: boolean;
retain?: boolean;
name: string;
certificateArn?: string;
certificateArn?: string | IntrinsicFunction;
hostedZoneId?: string;
hostedZoneName?: string;
route53?: boolean;
Expand Down