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

chore(integ-tests): add waiterProvider to IApiCall #27844

Merged
merged 14 commits into from
Dec 21, 2023
29 changes: 29 additions & 0 deletions packages/@aws-cdk/integ-tests-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,32 @@ const describe = testCase.assertions.awsApiCall('StepFunctions', 'describeExecut
});
```

In cases where the `waitForAssertions()` is used for the `awsApiCall`, the actual API call is executed
by the `waiterProvider`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In cases where the `waitForAssertions()` is used for the `awsApiCall`, the actual API call is executed
by the `waiterProvider`.
When `waitForAssertions()` is used for the `awsApiCall`, the actual API call is executed
by the `waiterProvider` assertion provider.


Same as `provider`, by default, the `AwsApiCall` construct will automatically add the correct IAM policies
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Same as `provider`, by default, the `AwsApiCall` construct will automatically add the correct IAM policies
By default, the `AwsApiCall` construct will automatically add the correct IAM policies

to allow the Lambda function to make the API call. It does this based on the `service`
and `api` that is provided. In the above example the service is `SQS` and the api is
`receiveMessage` so it will create a policy with `Action: 'sqs:ReceiveMessage`.

There are some cases where the permissions do not exactly match the service/api call, for
example the S3 `listObjectsV2` api. In these cases it is possible to add the correct policy
by accessing the `waiterProvider` object.

```ts
declare const integ: IntegTest;

const apiCall = integ.assertions.awsApiCall('S3', 'listObjectsV2', {
Bucket: 'mybucket',
}).waitForAssertions({
totalTimeout: Duration.minutes(5),
interval: Duration.seconds(15),
backoffRate: 3,
});

apiCall?.waiterProvider.addToRolePolicy({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
apiCall?.waiterProvider.addToRolePolicy({
apiCall.waiterProvider?.addToRolePolicy({

Effect: 'Allow',
Action: ['s3:GetObject', 's3:ListBucket'],
Resource: ['*'],
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { WaiterStateMachineOptions } from './waiter-state-machine';
*/
export interface IApiCall extends IConstruct {
/**
* access the AssertionsProvider. This can be used to add additional IAM policies
* the the provider role policy
* Access the AssertionsProvider. This can be used to add additional IAM policies
* to the provider role policy.
*
* @example
* declare const apiCall: AwsApiCall;
Expand All @@ -22,6 +22,21 @@ export interface IApiCall extends IConstruct {
*/
readonly provider: AssertionsProvider;

/**
* Access the AssertionsProvider for the waiter state machine.
* This can be used to add additional IAM policies
* to the provider role policy.
*
* @example
* declare const apiCall: AwsApiCall;
* apiCall.waiterProvider?.addToRolePolicy({
* Effect: 'Allow',
* Action: ['s3:GetObject'],
* Resource: ['*'],
* });
*/
readonly waiterProvider?: AssertionsProvider;

/**
* Returns the value of an attribute of the custom resource of an arbitrary
* type. Attributes are returned from the custom resource provider through the
Expand Down
13 changes: 0 additions & 13 deletions packages/@aws-cdk/integ-tests-alpha/lib/assertions/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,6 @@ export interface AwsApiCallProps extends AwsApiCallOptions { }
export class AwsApiCall extends ApiCallBase {
public readonly provider: AssertionsProvider;

/**
* access the AssertionsProvider for the waiter state machine.
* This can be used to add additional IAM policies
* the the provider role policy
*
* @example
* declare const apiCall: AwsApiCall;
* apiCall.waiterProvider?.addToRolePolicy({
* Effect: 'Allow',
* Action: ['s3:GetObject'],
* Resource: ['*'],
* });
*/
public waiterProvider?: AssertionsProvider;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the build is failing here. Can't remove this docstring entirely since its a public API. Why was it removed in the first place?

Copy link
Contributor Author

@go-to-k go-to-k Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I added it anyway.

I've moved the same explanation to IApiCall, and at few lines up public readonly provider: AssertionsProvider; had no docstring, so I removed this too. Why is it good that there is no docstring there (provider)?

export class AwsApiCall extends ApiCallBase {
  public readonly provider: AssertionsProvider;

I looked aws.json(packages/@aws-cdk/integ-tests-alpha/awslint.json), but could not find the property.

Copy link
Contributor Author

@go-to-k go-to-k Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood, that's because it's readonly.


protected readonly apiCallResource: CustomResource;
Expand Down

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,64 @@
{
"Resources": {
"Bucket83908E77": {
"Type": "AWS::S3::Bucket",
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
}
},
"Outputs": {
"ExportsOutputRefBucket83908E7781C90AC0": {
"Value": {
"Ref": "Bucket83908E77"
},
"Export": {
"Name": "WaiterProviderStack:ExportsOutputRefBucket83908E7781C90AC0"
}
},
"ExportsOutputFnGetAttBucket83908E77Arn063C8555": {
"Value": {
"Fn::GetAtt": [
"Bucket83908E77",
"Arn"
]
},
"Export": {
"Name": "WaiterProviderStack:ExportsOutputFnGetAttBucket83908E77Arn063C8555"
}
}
},
"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.

Loading