aws / aws/aws-cdk

(integ-tests-alpha): cannot assert `awsApiCall` with `@aws-sdk/client-api-gateway:TestInvokeMethodCommand`

Open
#32,635 3 comments 1 reaction 0 assignees View on GitHub
@aws-cdk/integ-tests bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

When defining an `awsApiCall` assertion on an API gateway resource using the `TestInvokeMethodCommand` action, the assertion fails with a permissions error.

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Last Known Working CDK Version

_No response_

### Expected Behavior

Expected the call to succeed

### Current Behavior

Getting a permissions error. See how its looking for the `apigateway:POST` action to be present in the policy.

```console
...is not authorized to perform: apigateway:POST on resource...
```

### Reproduction Steps

```ts
const api = ... // define a rest api gateway

integ.assertions.awsApiCall('@aws-sdk/client-api-gateway', 'TestInvokeMethodCommand', {
restApiId: api.restApiId,
resourceId: 'resourceId',
httpMethod: 'POST',
pathWithQueryString: '/path',
}, ['Body']);
```

### Possible Solution

In this case, the policy should be derived from the `httpMethod` parameter, and not the API command. Its not great because it completely diverges from the regular code path and introduces very special handling.

### Additional Information/Context

_No response_

### CDK CLI Version

2.173.2 (build f8e6207)

### Framework Version

2.173.1

### Node.js Version

v18.20.4

### OS

Mac

### Language

TypeScript

### Language Version

5.7.2

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the integ.assertions.awsApiCall assertion using TestInvokeMethodCommand and reproduce the permission failure from the TypeScript example. Trace how the policy action is derived for this command and compare it with the provided httpMethod. Done means the assertion succeeds without requiring the incorrect apigateway:POST permission.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
api, cloud, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.