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(stepfunctions-tasks): encryption is required for AthenaStartQueryExecution #11355

Merged
merged 5 commits into from
Nov 12, 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
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ export class AthenaStartQueryExecution extends sfn.TaskStateBase {
return policyStatements;
}

private renderEncryption(): any {
const encryptionConfiguration = this.props.resultConfiguration?.encryptionConfiguration !== undefined
? {
EncryptionOption: this.props.resultConfiguration.encryptionConfiguration.encryptionOption,
KmsKey: this.props.resultConfiguration.encryptionConfiguration.encryptionKey,
}
: undefined;

return encryptionConfiguration;
}

/**
* Provides the Athena start query execution service integration task configuration
*/
Expand All @@ -185,10 +196,7 @@ export class AthenaStartQueryExecution extends sfn.TaskStateBase {
Database: this.props.queryExecutionContext?.databaseName,
},
ResultConfiguration: {
EncryptionConfiguration: {
EncryptionOption: this.props.resultConfiguration?.encryptionConfiguration?.encryptionOption,
KmsKey: this.props.resultConfiguration?.encryptionConfiguration?.encryptionKey,
},
EncryptionConfiguration: this.renderEncryption(),
OutputLocation: `s3://${this.props.resultConfiguration?.outputLocation?.bucketName}/${this.props.resultConfiguration?.outputLocation?.objectKey}/`,
},
WorkGroup: this.props.workGroup,
Expand All @@ -205,10 +213,7 @@ export class AthenaStartQueryExecution extends sfn.TaskStateBase {
Database: this.props.queryExecutionContext?.databaseName,
},
ResultConfiguration: {
EncryptionConfiguration: {
EncryptionOption: this.props.resultConfiguration?.encryptionConfiguration?.encryptionOption,
KmsKey: this.props.resultConfiguration?.encryptionConfiguration?.encryptionKey,
},
EncryptionConfiguration: this.renderEncryption(),
},
WorkGroup: this.props.workGroup,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,56 @@ describe('Start Query Execution', () => {
},
});
});

test('no encryptionConfiguration', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
const task = new AthenaStartQueryExecution(stack, 'Query', {
queryString: 'CREATE DATABASE database',
clientRequestToken: 'unique-client-request-token',
queryExecutionContext: {
databaseName: 'mydatabase',
catalogName: 'AwsDataCatalog',
},
resultConfiguration: {
outputLocation: {
bucketName: 'query-results-bucket',
objectKey: 'folder',
},
},
workGroup: 'primary',
});

// THEN
expect(stack.resolve(task.toStateJson())).toEqual({
Type: 'Task',
Resource: {
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':states:::athena:startQueryExecution',
],
],
},
End: true,
Parameters: {
QueryString: 'CREATE DATABASE database',
ClientRequestToken: 'unique-client-request-token',
QueryExecutionContext: {
Database: 'mydatabase',
Catalog: 'AwsDataCatalog',
},
ResultConfiguration: {
OutputLocation: 's3://query-results-bucket/folder/',
},
WorkGroup: 'primary',
},
});
});
});