Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(appsync): HttpDataSource extends BackedDataSource instead of BaseDataSource #11185

Merged
merged 5 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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: 1 addition & 1 deletion packages/@aws-cdk/aws-appsync/lib/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export interface HttpDataSourceProps extends BaseDataSourceProps {
/**
* An AppSync datasource backed by a http endpoint
*/
export class HttpDataSource extends BaseDataSource {
export class HttpDataSource extends BackedDataSource {
constructor(scope: Construct, id: string, props: HttpDataSourceProps) {
const authorizationConfig = props.authorizationConfig ? {
authorizationType: 'AWS_IAM',
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-appsync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
"jest": "^26.6.3",
"pkglint": "0.0.0"
"pkglint": "0.0.0",
"@aws-cdk/aws-stepfunctions": "0.0.0"
},
"dependencies": {
"@aws-cdk/aws-cognito": "0.0.0",
Expand Down
73 changes: 72 additions & 1 deletion packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import '@aws-cdk/assert/jest';
import * as path from 'path';
import * as sfn from '@aws-cdk/aws-stepfunctions';
import * as cdk from '@aws-cdk/core';
import * as appsync from '../lib';

Expand Down Expand Up @@ -86,13 +87,84 @@ describe('Http Data Source configuration', () => {
});
});

test('other aws resources can grant http data source', () => {
// WHEN
const machineArn = 'arn:aws:states:us-east-1::stateMachine:hello';
const machine = sfn.StateMachine.fromStateMachineArn(stack, 'importedMachine', machineArn);
const ds = api.addHttpDataSource('ds', endpoint, {
name: 'custom',
description: 'custom description',
authorizationConfig: {
signingRegion: 'us-east-1',
signingServiceName: 'states',
},
});
machine.grantRead(ds);


// THEN
expect(stack).toHaveResourceLike('AWS::IAM::Policy', {
PolicyDocument: {
Statement: [
{
Action: [
'states:ListExecutions',
'states:ListStateMachines',
],
Effect: 'Allow',
Resource: machineArn,
},
{
Action: [
'states:DescribeExecution',
'states:DescribeStateMachineForExecution',
'states:GetExecutionHistory',
],
Effect: 'Allow',
Resource: {
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':states:',
{
Ref: 'AWS::Region',
},
':',
{
Ref: 'AWS::AccountId',
},
':execution:hello:*',
],
],
},
},
{
Action: [
'states:ListActivities',
'states:DescribeStateMachine',
'states:DescribeActivity',
],
Effect: 'Allow',
Resource: '*',
},
],
Version: '2012-10-17',
},
});
});

test('appsync errors when creating multiple http data sources with no configuration', () => {
// THEN
expect(() => {
api.addHttpDataSource('ds', endpoint);
api.addHttpDataSource('ds', endpoint);
}).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]");
});

});

describe('adding http data source from imported api', () => {
Expand Down Expand Up @@ -125,4 +197,3 @@ describe('adding http data source from imported api', () => {
});
});
});