aws / aws/serverless-application-model

API Usage Plan Generates (Unnecessary?) 'DependsOn'

Open
#1,541 4 comments 1 reaction 1 assignee Claimed by @GavinZZ View on GitHub
area/bestpractices maintainer/need-response
Dominant language
Python
Stars
9.6k
Forks
2.5k
Avg merge
1d 11h
Merged PRs (30d)
7

Description

**Description:**
Specifying an API usage plan will populate `DependsOn` with resources that are already included as a `Ref` in `Properties`. There are a couple of places where this currently occurs. To be clear, this doesn't break functionality but it does report as a warning in [cfn-lint](https://github.com/aws-cloudformation/cfn-python-lint) (which is how I came across this).

Is this extra `DependsOn` perhaps needed to handle a very specific use case? I'm more than happy to submit a fix if these extra declarations are not needed.

**Steps to reproduce the issue:**
1. This is demonstrated within the translator tests. For example, this [input](https://github.com/awslabs/serverless-application-model/blob/1b2d6f25514780d918b1bebf262ea05b89c5e646/tests/translator/input/api_with_usageplans.yaml) (which is head of `develop` at the time of this bug).

**Observed result:**
These are from the translator test outputs:

A couple of examples for usage plan resource:
https://github.com/awslabs/serverless-application-model/blob/1b2d6f25514780d918b1bebf262ea05b89c5e646/tests/translator/output/api_with_usageplans.json#L392-L430

https://github.com/awslabs/serverless-application-model/blob/1b2d6f25514780d918b1bebf262ea05b89c5e646/tests/translator/output/api_with_usageplans.json#L365-L391

And a couple of examples for usage plan key resource:
https://github.com/awslabs/serverless-application-model/blob/1b2d6f25514780d918b1bebf262ea05b89c5e646/tests/translator/output/api_with_usageplans.json#L83-L97

https://github.com/awslabs/serverless-application-model/blob/1b2d6f25514780d918b1bebf262ea05b89c5e646/tests/translator/output/api_with_usageplans.json#L530-L544

**Expected result:**
I would expect the usage plan resource to look like:

```
"MyApiTwoUsagePlan": {
"Type": "AWS::ApiGateway::UsagePlan",
"Properties": {
"ApiStages": [
{
"ApiId": {
"Ref": "MyApiTwo"
},
"Stage": {
"Ref": "MyApiTwoProdStage"
}
}
],
"Description": "Description for usage plan",
"Tags": [
{
"Value": "value1",
"Key": "key1"
},
{
"Value": "value2",
"Key": "key2"
}
],
"Quota": {
"Limit": 10,
"Period": "MONTH",
"Offset": 10
},
"Throttle": {
"RateLimit": 1000,
"BurstLimit": 1000
},
"UsagePlanName": "SomeRandomName"
}
},
```

```
"ServerlessUsagePlan": {
"Type": "AWS::ApiGateway::UsagePlan",
"Properties": {
"ApiStages": [
{
"ApiId": {
"Ref": "MyApiThree"
},
"Stage": {
"Ref": "MyApiThreeProdStage"
}
},
{
"ApiId": {
"Ref": "ServerlessRestApi"
},
"Stage": {
"Ref": "ServerlessRestApiProdStage"
}
}
]
}
},
```

And for usage plan key resources:
```
"MyApiTwoUsagePlanKey": {
"Type": "AWS::ApiGateway::UsagePlanKey",
"Properties": {
"KeyType": "API_KEY",
"KeyId": {
"Ref": "MyApiTwoApiKey"
},
"UsagePlanId": {
"Ref": "MyApiTwoUsagePlan"
}
}
},
```

```
"ServerlessUsagePlanKey": {
"Type": "AWS::ApiGateway::UsagePlanKey",
"Properties": {
"KeyType": "API_KEY",
"KeyId": {
"Ref": "ServerlessApiKey"
},
"UsagePlanId": {
"Ref": "ServerlessUsagePlan"
}
}
},
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.