From cda84b16741136b7175df21d90db3233debc745f Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Mon, 24 Apr 2017 20:47:11 +0200 Subject: [PATCH] provider/aws: Expose invoke ARN from Lambda function (for APIG) (#13890) --- builtin/providers/aws/resource_aws_lambda_function.go | 6 ++++++ builtin/providers/aws/structure.go | 6 ++++++ .../docs/providers/aws/r/lambda_function.html.markdown | 1 + 3 files changed, 13 insertions(+) diff --git a/builtin/providers/aws/resource_aws_lambda_function.go b/builtin/providers/aws/resource_aws_lambda_function.go index 4a1e72023..c7756c397 100644 --- a/builtin/providers/aws/resource_aws_lambda_function.go +++ b/builtin/providers/aws/resource_aws_lambda_function.go @@ -146,6 +146,10 @@ func resourceAwsLambdaFunction() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "invoke_arn": { + Type: schema.TypeString, + Computed: true, + }, "last_modified": { Type: schema.TypeString, Computed: true, @@ -406,6 +410,8 @@ func resourceAwsLambdaFunctionRead(d *schema.ResourceData, meta interface{}) err d.Set("version", lastVersion) d.Set("qualified_arn", lastQualifiedArn) + d.Set("invoke_arn", buildLambdaInvokeArn(*function.FunctionArn, meta.(*AWSClient).region)) + return nil } diff --git a/builtin/providers/aws/structure.go b/builtin/providers/aws/structure.go index 8bed3948a..f8c046dd2 100644 --- a/builtin/providers/aws/structure.go +++ b/builtin/providers/aws/structure.go @@ -2011,3 +2011,9 @@ func flattenCognitoIdentityProviders(ips []*cognitoidentity.Provider) []map[stri return values } + +func buildLambdaInvokeArn(lambdaArn, region string) string { + apiVersion := "2015-03-31" + return fmt.Sprintf("arn:aws:apigateway:%s:lambda:path/%s/functions/%s/invocations", + region, apiVersion, lambdaArn) +} diff --git a/website/source/docs/providers/aws/r/lambda_function.html.markdown b/website/source/docs/providers/aws/r/lambda_function.html.markdown index edb0a419d..ad6116e9f 100644 --- a/website/source/docs/providers/aws/r/lambda_function.html.markdown +++ b/website/source/docs/providers/aws/r/lambda_function.html.markdown @@ -108,6 +108,7 @@ For **environment** the following attributes are supported: * `arn` - The Amazon Resource Name (ARN) identifying your Lambda Function. * `qualified_arn` - The Amazon Resource Name (ARN) identifying your Lambda Function Version (if versioning is enabled via `publish = true`). +* `invoke_arn` - The ARN to be used for invoking Lambda Function from API Gateway - to be used in [`aws_api_gateway_integration`](/docs/providers/aws/r/api_gateway_integration.html)'s `uri` * `version` - Latest published version of your Lambda Function. * `last_modified` - The date this resource was last modified. * `kms_key_arn` - (Optional) The ARN for the KMS encryption key.