Skip to content

AWS Lambda permissions source_arn should allow wildcards #9972

Closed
@ghost

Description

This issue was originally opened by @bholzer as hashicorp/terraform#22670. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version

Terraform v0.12.7
+ provider.archive v1.2.2
+ provider.aws v2.22.0
+ provider.random v2.2.0

Terraform Configuration Files

resource "aws_lambda_permission" "farm_projects_index_lambda_permission" {
  statement_id  = "AllowExecutionFromAPIGateway"
  action        = "lambda:InvokeFunction"
  function_name = "${aws_lambda_function.farm_projects_index_lambda.function_name}"
  principal     = "apigateway.amazonaws.com"

  # More: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-control-access-using-iam-policies-to-invoke-api.html
  source_arn = "arn:aws:execute-api:${var.region}:*:${aws_api_gateway_rest_api.farm_api.id}/*/${aws_api_gateway_method.farm_projects_index.http_method}${aws_api_gateway_resource.farm_projects.path}"
}

Expected Behavior

AWS documentation (linked to by terraform docs) shows that wildcards are allowed for region and account ID for the resource expressions on lambda permissions:

arn:aws:execute-api:us-east-1:*:* for any resource path in any stage, for any API in the AWS region of us-east-1.

https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-control-access-using-iam-policies-to-invoke-api.html

Actual Behavior

Error: "source_arn" doesn't look like a valid ARN ("^arn:[\\w-]+:([a-zA-Z0-9\\-])+:([a-z]{2}-(gov-)?[a-z]+-\\d{1})?:(\\d{12})?:(.*)$"): "arn:aws:execute-api:us-east-1:*:cd4u48mqbh/*/GET/projects"

Appears the source_arn arg is validated by a regex that disallows for a wildcard in the region or account_id part of the ARN.

Steps to Reproduce

Create a lambda function, API gateway, API gateway resource and method, and use the lambda permission provided above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    service/lambdaIssues and PRs that pertain to the lambda service.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions