Skip to content

apigateway: AWS::ApiGateway::Method's physical ID is the HTTP verb, so two methods in one stack collide #843

Closed

Description

@scttfrdmn

AWS::ApiGateway::Method's physical ID is the HTTP verb, so every GET in a stack is the same resource.

What substrate does

deployAPIGatewayMethod records the verb as the physical ID
(emulator/cfn_resources_v19.go:239):

dr := DeployedResource{LogicalID: logicalID, Type: "AWS::ApiGateway::Method", PhysicalID: httpMethod}

httpMethod is the template's HttpMethod property — GET, POST, ANY. It carries
neither the REST API ID nor the resource ID, both of which the helper already has in hand
(restAPIID and resourceID, used to build the PUT /restapis/{id}/resources/{id}/methods/{verb}
path two lines above).

What that costs

A template with a GET on /pets and a GET on /pets/{id} — the ordinary shape — deploys
two AWS::ApiGateway::Method resources whose physical ID is the string GET for both. So:

What AWS documents

AWS::ApiGateway::Method, Return values → Ref:

When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns
the method ID, such as mysta-metho-01234b567890example.

That is a minted unique ID, not the verb, and it is the only return value the type
documents — the page has no Fn::GetAtt section at all.

Why it was recorded rather than fixed in #827

#827 fixed the values substrate retains somewhere. The method ID is not one: nothing in the
API Gateway plugin mints it, so Ref had nothing correct to resolve to. The divergence is
recorded in docs/services.md under "recorded rather than fixed":

AWS::ApiGateway::Method — the documented value is the method's ID, which substrate does
not mint; the physical ID is the HTTP verb. Every GET method in a stack therefore shares
one physical ID.

Filing it separately because minting the ID is a change to the API Gateway plugin's own
PutMethod, not to the intrinsic resolver — the same reason Ref was not allowed to change
PhysicalID.

Acceptance criteria

  • The API Gateway plugin mints a method ID on PutMethod, in AWS's shape (a short
    opaque string; AWS's example is mysta-metho-01234b567890example) and derived
    deterministically from the request so a replay produces the same one.
  • GetMethod reports it, so a caller can read back what a stack created.
  • deployAPIGatewayMethod records the minted ID as PhysicalID; the verb, REST API ID
    and resource ID go to dr.Metadata if they are needed by a resolver.
  • !Ref on a method resolves to the method ID.
  • Two methods on different resources of the same API have different physical IDs, and
    DescribeStackResources reports both.
  • The docs/services.md "recorded rather than fixed" entry for the type is removed and
    the Ref table row is corrected.
  • Whether AWS::CloudFront::CloudFrontOriginAccessIdentity (the same defect: the physical
    ID is the configured Comment) is fixed here or separately is decided and recorded.

Activity

  1. added this to the v0.115.0 milestone on Sep 13, 2026
  2. added
    type: bug
    area: cloudformation
    on Sep 13, 2026
  3. scttfrdmn commented on Sep 14, 2026

    @scttfrdmn
    OwnerAuthor

    Researched this before implementing. The core defect verifies exactly, and two of the issue's criteria are unimplementable within substrate's scope and are reversed with citations. Recording that here before the PR.

    The defect verifies, and is worse than the issue states

    emulator/cfn_resources_v19.go:239 sets PhysicalID: httpMethod, so every AWS::ApiGateway::Method in a stack is identified by its HTTP verb. Two methods with the same verb on different resources are indistinguishable in DescribeStackResources.

    And because a PhysicalResourceId-only request scans every stack in the account (cloudformation_plugin.go:632-636, filter at :661), describe-stack-resources --physical-resource-id GET returns every GET method in every stack, not just the one asked about. !Ref on a Method resolves to the verb too (cfn_deployer.go:5222-5226 — cfnRefValue has no arm for the type, so Ref falls through to the physical ID).

    AWS's Template Reference is unambiguous, and this is the whole warrant for the fix:

    When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns the method ID, such as mysta-metho-01234b567890example.

    That is CloudFormation's own generated-physical-name shape — {stack}-{logical}-{suffix}, segments truncated, lowercased.

    Reversed: the two criteria asking the API Gateway plugin to mint a method ID

    AWS's REST API has no method identifier. API_Method's members are exactly the eleven configuration fields with no id, and API_PutMethod returns those members with no identifier at all — its sample response carries only _links, apiKeyRequired, authorizationType and httpMethod. Asking the plugin to mint and return a method ID would invent a member AWS does not publish, which is out of scope under #671.

    The plugin also already keys methods correctly: apigwMethodKey(accountID, region, apiID, resID, verb) (apigateway_types.go:284-286) disambiguates fully. There is no service-state collision here at all — the defect is purely in the CloudFormation layer's reported identifier.

    So the fix is entirely CFN-side, and it needs no new mechanism: cfnGeneratedName (cfn_physical_name.go:108) already produces exactly AWS's documented shape, deterministically, with the suffix derived by FNV-64a rather than randomly — for the reason its own doc comment gives, that UpdateStack in substrate is a re-Deploy, so a random suffix would change on every update. AWS::ApiGateway::Method is simply absent from cfnGeneratedNameTypes. No plugin change, and no cfnRefValue arm either, because AWS's Ref is the method ID.

    The load-bearing consequence, and a correction to how the plan said to handle it

    cfn_delete.go:313 builds the DELETE path using the physical ID as the verb, with :306 documenting that. Changing the physical ID breaks stack deletion for every Method unless the deleter sources the verb in the same commit — which it does.

    The verb comes from props, not from dr.Metadata, and the reason is this page: AWS::ApiGateway::Method has no Fn::GetAtt section at all. dr.Metadata is a generic GetAtt channel — cfnGetAttValue's step 2 resolves any metadata key by its own name (cfn_intrinsics.go:150-158) — so recording HttpMethod there would make !GetAtt MyMethod.HttpMethod resolve to a value AWS does not publish an attribute for. That is the same "invent a member AWS does not have" defect this release fixed in IAM's permissions boundary, so it is not the channel to use.

    props has no such cost and no durability disadvantage: the deleter already sources RestApiId and ResourceId from it, delete-time props come from the stored stack.TemplateBody (cfn_delete.go:725-732) rather than a live template, and when that template no longer parses the deleter already returns nil for a Method because it cannot resolve the API and resource IDs. So Metadata would buy nothing the deleter can act on. Deploy and delete now resolve the verb through one helper so they cannot drift.

    Also overstated in the issue

    • There is no redeploy physical-ID fallback — (*CFNStackState).deployedResource (cfn_deployer.go:437) matches on logical ID, and recognition is clearUnchangedRedeploys (cfn_rollback.go:209), whose own comment explains why the physical ID cannot be the key.
    • cctx.resources is keyed by logical ID, so nothing there is affected.
    • There is no Method arm in cfnResolveStampTarget, so the aws:cloudformation:* stamp cannot collide either.

    The sibling defect in the last criterion: verified, and worse than described — filing separately

    deployCloudFrontOAI (cfn_resources_v23.go:101-114) is now checked against aws-resource-cloudfront-cloudfrontoriginaccessidentity.html, which says:

    Ref returns the origin access identity, such as E15MNIMTCFKK4C.

    Two findings, not one. The issue says the physical ID is the comment; in fact it is the logical ID, because resolveStringProp(props, "CloudFrontOriginAccessIdentityConfig.Comment", logicalID, cctx) looks up a dotted key in a flat map and CloudFrontOriginAccessIdentityConfig is a nested object, so the lookup never matches and the fallback always wins. Either way it is not an OAI ID.

    This is not folded into this PR, deliberately. The helper is a pure stub — it dispatches no request at all — and fixing it properly means deciding how to mint an E-prefixed 14-character identifier deterministically (a format AWS publishes only by example, so cfnGeneratedName's {stack}-{logical}-{suffix} shape is wrong for it), plus whether the two documented Fn::GetAtt attributes — Id and S3CanonicalUserId — should resolve. That is its own decision with its own citation, so it gets its own issue rather than riding along here.

    One more finding, recorded not fixed

    HttpMethod is Required: Yes on this type, and deployAPIGatewayMethod defaults it to "GET" when absent. Defaulting a required member is the same defect class as #755's CreateIPSet, but CloudFormation-side required-property validation is a general feature substrate does not have anywhere, so widening this issue to add it for one type would be inconsistent rather than complete. Recorded here so it is not lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: apigatewayarea: cloudformationtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions