diff --git a/README.md b/README.md index e9aa97b..d3306a7 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ The example below shows how to add them as dependencies in your `build.gradle` f ```groovy dependencies { - implementation("com.newrelic.opentracing:newrelic-java-lambda:2.0.0") - implementation("com.newrelic.opentracing:java-aws-lambda:2.0.0") + implementation("com.newrelic.opentracing:newrelic-java-lambda:2.1.1") + implementation("com.newrelic.opentracing:java-aws-lambda:2.1.0") } ``` @@ -34,8 +34,8 @@ The New Relic Lambda Tracer and SDK support different versions of OpenTracing as * Lambda Tracer: [com.newrelic.opentracing:newrelic-java-lambda:1.1.1](https://search.maven.org/artifact/com.newrelic.opentracing/newrelic-java-lambda/1.1.1/jar) * Lambda SDK: [com.newrelic.opentracing:java-aws-lambda:1.0.0](https://search.maven.org/artifact/com.newrelic.opentracing/java-aws-lambda/1.0.0/jar) * OpenTracing `0.32.0`, `0.33.0`: - * Lambda Tracer: [com.newrelic.opentracing:newrelic-java-lambda:2.0.0](https://search.maven.org/artifact/com.newrelic.opentracing/newrelic-java-lambda/2.0.0/jar) - * Lambda SDK: [com.newrelic.opentracing:java-aws-lambda:2.0.0](https://search.maven.org/artifact/com.newrelic.opentracing/java-aws-lambda/2.0.0/jar) + * Lambda Tracer: [com.newrelic.opentracing:newrelic-java-lambda:2.1.1](https://search.maven.org/artifact/com.newrelic.opentracing/newrelic-java-lambda/2.0.0/jar) + * Lambda SDK: [com.newrelic.opentracing:java-aws-lambda:2.1.0](https://search.maven.org/artifact/com.newrelic.opentracing/java-aws-lambda/2.0.0/jar) ## Getting Started @@ -47,8 +47,10 @@ For full details on getting started please see the documentation on how to [Enab package com.handler.example; import com.amazonaws.services.lambda.runtime.Context; +import com.amazonaws.services.lambda.runtime.RequestHandler; import io.opentracing.util.GlobalTracer; import com.newrelic.opentracing.aws.TracingRequestHandler; +import com.newrelic.opentracing.aws.LambdaTracing; import com.newrelic.opentracing.LambdaTracer; import java.util.Map; @@ -59,7 +61,7 @@ import java.util.Map; * @param Map The Lambda Function input * @param String The Lambda Function output */ -public class MyLambdaHandler implements TracingRequestHandler, String> { +public class MyLambdaHandler implements RequestHandler, String> { static { // Register the New Relic OpenTracing LambdaTracer as the Global Tracer GlobalTracer.registerIfAbsent(LambdaTracer.INSTANCE); @@ -74,8 +76,10 @@ public class MyLambdaHandler implements TracingRequestHandler input, Context context) { - // TODO Your function logic here - return "Lambda Function output"; + return LambdaTracing.instrument(apiGatewayProxyRequestEvent, context, (event, ctx) -> { + // TODO Your function logic here + return "Lambda Function output"; + }); } } ``` diff --git a/examples/distributed-tracing-example/DTCalleeFunction/build.gradle b/examples/distributed-tracing-example/DTCalleeFunction/build.gradle index 1e093e6..dea2e5d 100644 --- a/examples/distributed-tracing-example/DTCalleeFunction/build.gradle +++ b/examples/distributed-tracing-example/DTCalleeFunction/build.gradle @@ -4,26 +4,33 @@ plugins { repositories { mavenCentral() + mavenLocal() } + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + dependencies { // New Relic AWS Lambda OpenTracing instrumentation - compile('com.newrelic.opentracing:java-aws-lambda:2.0.0') - compile('com.newrelic.opentracing:newrelic-java-lambda:2.0.0') + implementation('com.newrelic.opentracing:java-aws-lambda:2.1.0') + implementation('com.newrelic.opentracing:newrelic-java-lambda:2.1.1') // OpenTracing - compile('io.opentracing:opentracing-util:0.33.0') + implementation('io.opentracing:opentracing-util:0.33.0') // JSON processing - compile('com.googlecode.json-simple:json-simple:1.1') + implementation('com.googlecode.json-simple:json-simple:1.1') // AWS Lambda Java SDK - compile('com.amazonaws:aws-lambda-java-log4j:1.0.0') - compile('com.amazonaws:aws-lambda-java-events:2.2.2') - compile('com.amazonaws:aws-java-sdk-lambda:1.11.608') + implementation('com.amazonaws:aws-lambda-java-log4j:1.0.0') + implementation('com.amazonaws:aws-lambda-java-events:2.2.2') + implementation('com.amazonaws:aws-java-sdk-lambda:1.11.608') implementation 'com.amazonaws:aws-lambda-java-core:1.2.0' // HTTP client - compile('com.konghq:unirest-java:3.0.00') + implementation('com.konghq:unirest-java:3.0.00') testImplementation 'junit:junit:4.12' -} \ No newline at end of file +} diff --git a/examples/distributed-tracing-example/DTCalleeFunction/src/main/java/com/example/DTCalleeFunction.java b/examples/distributed-tracing-example/DTCalleeFunction/src/main/java/com/example/DTCalleeFunction.java index 807f461..e8de7a1 100644 --- a/examples/distributed-tracing-example/DTCalleeFunction/src/main/java/com/example/DTCalleeFunction.java +++ b/examples/distributed-tracing-example/DTCalleeFunction/src/main/java/com/example/DTCalleeFunction.java @@ -6,19 +6,20 @@ package com.example; import com.amazonaws.services.lambda.runtime.Context; +import com.amazonaws.services.lambda.runtime.RequestHandler; +import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; +import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; import com.newrelic.opentracing.LambdaTracer; -import com.newrelic.opentracing.aws.TracingRequestHandler; +import com.newrelic.opentracing.aws.LambdaTracing; import io.opentracing.util.GlobalTracer; import org.apache.log4j.Logger; -import java.util.Map; - /** * AWS Lambda function that utilizes the AWS Lambda OpenTracing SDK and New Relic AWS Lambda OpenTracing Tracer. *

* This function simply prints out the input and headers map it received from API Gateway when invoked. */ -public class DTCalleeFunction implements TracingRequestHandler, Map> { +public class DTCalleeFunction implements RequestHandler { static { GlobalTracer.registerIfAbsent(LambdaTracer.INSTANCE); } @@ -28,20 +29,25 @@ public class DTCalleeFunction implements TracingRequestHandler doHandleRequest(Map input, Context context) { - // Log Lambda function input details received from API Gateway to the Cloudwatch logs - if (input != null && !input.isEmpty()) { - LOG.info("Lambda function input: " + input); - LOG.info("Headers: " + input.get("headers")); - } else { - LOG.info("Lambda function did not receive any input"); - } + public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context ctx) { + return LambdaTracing.instrument(event, ctx, (input, context) -> { + // Log Lambda function input details received from API Gateway to the Cloudwatch logs + if (input != null) { + LOG.info("Lambda function input: " + input); + LOG.info("Headers: " + input.getHeaders()); + } else { + LOG.info("Lambda function did not receive any input"); + } + APIGatewayProxyResponseEvent ret = new APIGatewayProxyResponseEvent() + .withStatusCode(200) + .withBody("OK"); - return new Response(200, "OK").getMap(); + return ret; + }); } } diff --git a/examples/distributed-tracing-example/DTCalleeFunction/src/test/java/com/example/DTCalleeFunctionTest.java b/examples/distributed-tracing-example/DTCalleeFunction/src/test/java/com/example/DTCalleeFunctionTest.java index b1c28a7..3b02520 100644 --- a/examples/distributed-tracing-example/DTCalleeFunction/src/test/java/com/example/DTCalleeFunctionTest.java +++ b/examples/distributed-tracing-example/DTCalleeFunction/src/test/java/com/example/DTCalleeFunctionTest.java @@ -5,6 +5,8 @@ package com.example; +import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; +import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; import org.junit.BeforeClass; import org.junit.Test; @@ -45,19 +47,15 @@ public void successfulResponse() { * priority=1.112115 * } */ - Map newrelicHeader = new HashMap() {{ - put(NR_DT_HEADER_KEY, NR_DT_HEADER_PAYLOAD); - }}; + Map newrelicHeader = Collections.singletonMap(NR_DT_HEADER_KEY, NR_DT_HEADER_PAYLOAD); - Map headers = new HashMap() {{ - put("headers", newrelicHeader); - }}; + APIGatewayProxyRequestEvent requestEvent = new APIGatewayProxyRequestEvent().withHeaders(newrelicHeader); DTCalleeFunction calleeFunction = new DTCalleeFunction(); - final Map responseMap = calleeFunction.handleRequest(headers, new TestContext()); + final APIGatewayProxyResponseEvent response = calleeFunction.handleRequest(requestEvent, new TestContext()); - assertEquals(200, responseMap.get("statusCode")); - assertEquals("OK", responseMap.get("body")); + assertEquals(200, response.getStatusCode().intValue()); + assertEquals("OK", response.getBody()); } private static void setEnvironmentVariables(Map environmentVariables) { diff --git a/examples/distributed-tracing-example/DTCallerFunction/build.gradle b/examples/distributed-tracing-example/DTCallerFunction/build.gradle index ac15745..4e4aac3 100644 --- a/examples/distributed-tracing-example/DTCallerFunction/build.gradle +++ b/examples/distributed-tracing-example/DTCallerFunction/build.gradle @@ -4,26 +4,33 @@ plugins { repositories { mavenCentral() + mavenLocal() } + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + dependencies { // New Relic AWS Lambda OpenTracing instrumentation - compile('com.newrelic.opentracing:java-aws-lambda:2.0.0') - compile('com.newrelic.opentracing:newrelic-java-lambda:2.0.0') + implementation('com.newrelic.opentracing:java-aws-lambda:2.1.0') + implementation('com.newrelic.opentracing:newrelic-java-lambda:2.1.1') // OpenTracing - compile('io.opentracing:opentracing-util:0.33.0') + implementation('io.opentracing:opentracing-util:0.33.0') // JSON processing - compile('com.googlecode.json-simple:json-simple:1.1') + implementation('com.googlecode.json-simple:json-simple:1.1') // AWS Lambda Java SDK - compile('com.amazonaws:aws-lambda-java-log4j:1.0.0') - compile('com.amazonaws:aws-lambda-java-events:2.2.2') - compile('com.amazonaws:aws-java-sdk-lambda:1.11.608') + implementation('com.amazonaws:aws-lambda-java-log4j:1.0.0') + implementation('com.amazonaws:aws-lambda-java-events:2.2.2') + implementation('com.amazonaws:aws-java-sdk-lambda:1.11.608') implementation 'com.amazonaws:aws-lambda-java-core:1.2.0' // HTTP client - compile('com.konghq:unirest-java:3.0.00') + implementation('com.konghq:unirest-java:3.0.00') testImplementation 'junit:junit:4.12' } diff --git a/examples/distributed-tracing-example/DTCallerFunction/src/main/java/com/example/DTCallerFunction.java b/examples/distributed-tracing-example/DTCallerFunction/src/main/java/com/example/DTCallerFunction.java index aaa59d6..fafcf2f 100644 --- a/examples/distributed-tracing-example/DTCallerFunction/src/main/java/com/example/DTCallerFunction.java +++ b/examples/distributed-tracing-example/DTCallerFunction/src/main/java/com/example/DTCallerFunction.java @@ -6,9 +6,11 @@ package com.example; import com.amazonaws.services.lambda.runtime.Context; +import com.amazonaws.services.lambda.runtime.RequestHandler; +import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; import com.newrelic.opentracing.LambdaTracer; -import com.newrelic.opentracing.aws.TracingRequestHandler; +import com.newrelic.opentracing.aws.LambdaTracing; import io.opentracing.Scope; import io.opentracing.Span; import io.opentracing.Tracer; @@ -30,7 +32,7 @@ *

* This function makes an external call to an API Gateway Proxy to invoke another AWS lambda function. */ -public class DTCallerFunction implements TracingRequestHandler, APIGatewayProxyResponseEvent> { +public class DTCallerFunction implements RequestHandler { static { GlobalTracer.registerIfAbsent(LambdaTracer.INSTANCE); } @@ -43,36 +45,38 @@ public class DTCallerFunction implements TracingRequestHandler input, Context context) { - final HttpResponse response; - - // Log Lambda function input details received from API Gateway to the Cloudwatch logs - if (input != null && !input.isEmpty()) { - LOG.info("Lambda function input: " + input); - LOG.info("Headers: " + input.get("headers")); - } else { - LOG.info("Lambda function did not receive any input"); - } + public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context ctx) { + return LambdaTracing.instrument(event, ctx, (input, context) -> { + final HttpResponse response; + + // Log Lambda function input details received from API Gateway to the Cloudwatch logs + if (input != null) { + LOG.info("Lambda function input: " + input); + LOG.info("Headers: " + input.getHeaders()); + } else { + LOG.info("Lambda function did not receive any input"); + } - final String dtCalleeApiGatewayProxyURL = System.getenv(API_GATEWAY_PROXY_URL); + final String dtCalleeApiGatewayProxyURL = System.getenv(API_GATEWAY_PROXY_URL); - if (dtCalleeApiGatewayProxyURL == null) { - LOG.error("The API_GATEWAY_PROXY_URL environment variable must be set to properly invoke DTCalleeLambda"); - return new APIGatewayProxyResponseEvent() - .withBody("Bad Request: The API_GATEWAY_PROXY_URL environment variable must be set to properly invoke DTCalleeLambda") - .withStatusCode(400); - } - response = makeExternalCallToApiGateway(dtCalleeApiGatewayProxyURL); + if (dtCalleeApiGatewayProxyURL == null) { + LOG.error("The API_GATEWAY_PROXY_URL environment variable must be set to properly invoke DTCalleeLambda"); + return new APIGatewayProxyResponseEvent() + .withBody("Bad Request: The API_GATEWAY_PROXY_URL environment variable must be set to properly invoke DTCalleeLambda") + .withStatusCode(400); + } + response = makeExternalCallToApiGateway(dtCalleeApiGatewayProxyURL); - return new APIGatewayProxyResponseEvent() - .withBody(response.getBody()) - .withStatusCode(response.getStatus()) - .withHeaders(getResponseHeaderMap(response)); + return new APIGatewayProxyResponseEvent() + .withBody(response.getBody()) + .withStatusCode(response.getStatus()) + .withHeaders(getResponseHeaderMap(response)); + }); } /** @@ -130,7 +134,7 @@ private HttpResponse makeExternalCallToApiGateway(String dtCalleeApiGate * @param response HttpResponse * @return Map of headers */ - private Map getResponseHeaderMap(HttpResponse response) { + private Map getResponseHeaderMap(HttpResponse response) { final List

headerList = response.getHeaders().all(); final Map headerMap = new HashMap<>(); headerList.forEach((header) -> headerMap.put(header.getName(), header.getValue())); diff --git a/examples/distributed-tracing-example/DTCallerFunction/src/test/java/com/example/DTCallerFunctionTest.java b/examples/distributed-tracing-example/DTCallerFunction/src/test/java/com/example/DTCallerFunctionTest.java index 4cce8e7..9d1e3f1 100644 --- a/examples/distributed-tracing-example/DTCallerFunction/src/test/java/com/example/DTCallerFunctionTest.java +++ b/examples/distributed-tracing-example/DTCallerFunction/src/test/java/com/example/DTCallerFunctionTest.java @@ -8,6 +8,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; import org.junit.BeforeClass; import org.junit.Test; @@ -50,16 +51,13 @@ public void successfulResponse() { * priority=1.112115 * } */ - Map newrelicHeader = new HashMap() {{ - put(NR_DT_HEADER_KEY, NR_DT_HEADER_PAYLOAD); - }}; + Map newrelicHeader = Collections.singletonMap(NR_DT_HEADER_KEY, NR_DT_HEADER_PAYLOAD); - Map headers = new HashMap() {{ - put("headers", newrelicHeader); - }}; + APIGatewayProxyRequestEvent input = new APIGatewayProxyRequestEvent() + .withHeaders(newrelicHeader); DTCallerFunction callerFunction = new DTCallerFunction(); - final APIGatewayProxyResponseEvent apiGatewayProxyResponseEvent = callerFunction.handleRequest(headers, new TestContext()); + final APIGatewayProxyResponseEvent apiGatewayProxyResponseEvent = callerFunction.handleRequest(input, new TestContext()); assertEquals(Integer.valueOf(200), apiGatewayProxyResponseEvent.getStatusCode()); assertEquals("OK", apiGatewayProxyResponseEvent.getBody()); diff --git a/examples/distributed-tracing-example/README.md b/examples/distributed-tracing-example/README.md index 9489448..f74592d 100644 --- a/examples/distributed-tracing-example/README.md +++ b/examples/distributed-tracing-example/README.md @@ -31,7 +31,7 @@ The AWS Toolkit is an open source plug-in for popular IDEs that uses the SAM CLI ## Usage/Installation -For full details on using the OpenTracing AWS Lambda SDK and Tracer please refer to the [main project README](../../README.md). This README supplements the main project README by documenting details specific to the example application such as using the SAM CLI and configuring an AWS API Gateway proxy to invoke Lambda functions. +For full details on using the OpenTracing AWS Lambda SDK and Tracer please refer to the [main project README](../../README.md). This README supplements the main project README by documenting details specific to the example application such as using the SAM CLI. ## Intellij ### Import Gradle projects @@ -42,8 +42,6 @@ When opening the project in Intellij for the first time you will likely need to To run the `DTCallerFunction` and `DTCalleeFunction` locally using the AWS Toolkit Intellij plugin, the run configurations for each function should be configured with your AWS Connection credentials, the specified environment variables/values, and use the provided `events/request-input.json` test event as follows: -**Note**: See the section on [configuring an API Gateway proxy to invoke Lambda functions](#configure-api-gateway-proxy-to-invoke-lambda-functions) for details on how to generate the url assigned to the `API_GATEWAY_PROXY_URL` environment variable. If you incorrectly configure `API_GATEWAY_PROXY_URL` in the run configuration for `DTCallerFunction` it will return a `400` response code when attempting to make an external call to `DTCalleeFunction`. When `API_GATEWAY_PROXY_URL` is configured properly a `200` response code should be returned. - DTCallerFunction Run Config ![dt-caller-function-run-config](readme-resources/dt-caller-function-run-config.png?raw=true "DTCallerFunction Run Config") @@ -79,24 +77,32 @@ To prepare the application for deployment, use the `sam package` command. ```bash sam package --output-template-file packaged.yaml --s3-bucket BUCKET_NAME -``` +``` -The SAM CLI creates deployment packages, uploads them to the S3 bucket, and creates a new version of the template that refers to the artifacts in the bucket. +The SAM CLI creates deployment packages for the Lambda function code, uploads them to the S3 bucket, and creates a new version of the template that refers to the artifacts in the bucket. The generated `packaged.yaml` file contains the IDs and resource URIs to utilize the artifacts that are uploaded to S3. The Lambda service loads code only from S3 buckets in the same region as the function. To deploy the application, use the `sam deploy` command. ```bash -sam deploy --template-file packaged.yaml --stack-name AWS --capabilities CAPABILITY_IAM +sam deploy --template-file packaged.yaml --stack-name NewRelicExample-JavaDT --capabilities CAPABILITY_IAM ``` +This will deploy the CloudFormation template to your AWS account, in your default region. At the end of the process, you should see a section like this: + + Outputs + ------------------------------------------------------------------------------------------------- + Key CallerEndpoint + Description New Relic DT example testing stage caller endpoint + Value https://abcde12345.execute-api.us-east-1.amazonaws.com/testing/dt-caller + +**Note:** Your URL will be different. A GET request to this URL (e.g. using a browser, or `curl`) will invoke the "Caller" Lambda function, which will invoke the "Callee" function in turn. + After deployment is complete you can run the following command to view the Stack: ```bash -aws cloudformation describe-stacks --stack-name AWS +aws cloudformation describe-stacks --stack-name NewRelicExample-JavaDT ``` -Note: the generated `packaged.yaml` file contains the IDs and resource URIs to utilize the artifacts that are uploaded to s3. - ### Use the SAM CLI to build and test locally Build your application with the `sam build` command. @@ -125,12 +131,14 @@ curl http://localhost:3000/ The SAM CLI reads the application template to determine the API's routes and the functions that they invoke. The `Events` property on each function's definition includes the route and method for each path. ```yaml - Events: - HelloWorld: - Type: Api - Properties: - Path: /hello - Method: get + Events: + CallerApi: + Type: Api + Properties: + Path: /dt-caller + Method: get + RestApiId: + Ref: ApiGatewayApiCaller ``` ### Add a resource to your application @@ -140,10 +148,10 @@ The application template uses AWS Serverless Application Model (AWS SAM) to defi To simplify troubleshooting, SAM CLI has a command called `sam logs`. `sam logs` lets you fetch logs generated by your deployed Lambda function from the command line. In addition to printing the logs on the terminal, this command has several nifty features to help you quickly find the bug. -`NOTE`: This command works for all AWS Lambda functions; not just the ones you deploy using SAM. +**NOTE**: This command works for all AWS Lambda functions; not just the ones you deploy using SAM. ```bash -sam logs -n DTCallerFunction --stack-name AWS --tail +sam logs -n DTCallerFunction --stack-name NewRelicExample-JavaDT --tail ``` You can find more information and examples about filtering Lambda function logs in the [SAM CLI Documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-logging.html). @@ -153,7 +161,7 @@ You can find more information and examples about filtering Lambda function logs To delete the sample application and the bucket that you created, use the AWS CLI. ```bash -aws cloudformation delete-stack --stack-name AWS +aws cloudformation delete-stack --stack-name NewRelicExample-JavaDT aws s3 rb s3://BUCKET_NAME ``` @@ -171,43 +179,3 @@ Tests are defined in the `DTCallerFunction/src/test` folder in this project. cd DTCallerFunction DTCallerFunction$ gradle test ``` - -## Configure API Gateway proxy to invoke Lambda functions -Documentation of how to configure the API Gateway proxy to invoke Lambda functions in this example. This is not intended to be a definitive guide on the recommended approach. - -Step 1: Create API -![1-create-api](readme-resources/1-create-api.png?raw=true "Create Api") - -Step 2: Configure the API -![2-name-api](readme-resources/2-name-api.png?raw=true "Name Api") - -Step 3: Create Resource -![3-create-resource](readme-resources/3-create-resource.png?raw=true "Create Resource") - -Step 4: Configure Resource -![4-create-resource](readme-resources/4-create-resource.png?raw=true "Create Resource Cont") - -Step 5: Create Method -![5-create-method](readme-resources/5-create-method.png?raw=true "Create Method") - -Step 6: Set HTTP Method Type -![6-create-method](readme-resources/6-create-method.png?raw=true "Create Method Cont") - -Step 7: Use Lambda Proxy Integration. This will allow headers to pass through as the Lambda function Input. -![7-setup-proxy-integration](readme-resources/7-setup-proxy-integration.png?raw=true "Setup Proxy") - -Step 8: Add Permission to invoke lambda function -![8-add-permissions](readme-resources/8-add-permissions.png?raw=true "Add Permissions") - -Step 9: Deploy API -![9-deploy-api](readme-resources/9-deploy-api.png?raw=true "Deploy Api") - -Step 10: Choose Stage for deployment -![10-deploy-api](readme-resources/10-deploy-api.png?raw=true "Deploy Api Cont") - -Step 11: Invoke URL is found in the Stage -![11-invoke-url](readme-resources/11-invoke-url.png?raw=true "Invoke Url") - -Step 12: Example URL invocation -![12-invoke-url](readme-resources/12-invoke-url.png?raw=true "Invoke Url Cont") - diff --git a/examples/distributed-tracing-example/readme-resources/1-create-api.png b/examples/distributed-tracing-example/readme-resources/1-create-api.png deleted file mode 100644 index b27c4f6..0000000 Binary files a/examples/distributed-tracing-example/readme-resources/1-create-api.png and /dev/null differ diff --git a/examples/distributed-tracing-example/readme-resources/10-deploy-api.png b/examples/distributed-tracing-example/readme-resources/10-deploy-api.png deleted file mode 100644 index 65e3596..0000000 Binary files a/examples/distributed-tracing-example/readme-resources/10-deploy-api.png and /dev/null differ diff --git a/examples/distributed-tracing-example/readme-resources/11-invoke-url.png b/examples/distributed-tracing-example/readme-resources/11-invoke-url.png deleted file mode 100644 index e99d3a2..0000000 Binary files a/examples/distributed-tracing-example/readme-resources/11-invoke-url.png and /dev/null differ diff --git a/examples/distributed-tracing-example/readme-resources/12-invoke-url.png b/examples/distributed-tracing-example/readme-resources/12-invoke-url.png deleted file mode 100644 index 9e9e048..0000000 Binary files a/examples/distributed-tracing-example/readme-resources/12-invoke-url.png and /dev/null differ diff --git a/examples/distributed-tracing-example/readme-resources/2-name-api.png b/examples/distributed-tracing-example/readme-resources/2-name-api.png deleted file mode 100644 index 4821fe1..0000000 Binary files a/examples/distributed-tracing-example/readme-resources/2-name-api.png and /dev/null differ diff --git a/examples/distributed-tracing-example/readme-resources/3-create-resource.png b/examples/distributed-tracing-example/readme-resources/3-create-resource.png deleted file mode 100644 index f9acb27..0000000 Binary files a/examples/distributed-tracing-example/readme-resources/3-create-resource.png and /dev/null differ diff --git a/examples/distributed-tracing-example/readme-resources/4-create-resource.png b/examples/distributed-tracing-example/readme-resources/4-create-resource.png deleted file mode 100644 index 029d417..0000000 Binary files a/examples/distributed-tracing-example/readme-resources/4-create-resource.png and /dev/null differ diff --git a/examples/distributed-tracing-example/readme-resources/5-create-method.png b/examples/distributed-tracing-example/readme-resources/5-create-method.png deleted file mode 100644 index 539d1ff..0000000 Binary files a/examples/distributed-tracing-example/readme-resources/5-create-method.png and /dev/null differ diff --git a/examples/distributed-tracing-example/readme-resources/6-create-method.png b/examples/distributed-tracing-example/readme-resources/6-create-method.png deleted file mode 100644 index eac1aae..0000000 Binary files a/examples/distributed-tracing-example/readme-resources/6-create-method.png and /dev/null differ diff --git a/examples/distributed-tracing-example/readme-resources/7-setup-proxy-integration.png b/examples/distributed-tracing-example/readme-resources/7-setup-proxy-integration.png deleted file mode 100644 index 4b19103..0000000 Binary files a/examples/distributed-tracing-example/readme-resources/7-setup-proxy-integration.png and /dev/null differ diff --git a/examples/distributed-tracing-example/readme-resources/8-add-permissions.png b/examples/distributed-tracing-example/readme-resources/8-add-permissions.png deleted file mode 100644 index 365e793..0000000 Binary files a/examples/distributed-tracing-example/readme-resources/8-add-permissions.png and /dev/null differ diff --git a/examples/distributed-tracing-example/readme-resources/9-deploy-api.png b/examples/distributed-tracing-example/readme-resources/9-deploy-api.png deleted file mode 100644 index bf8e917..0000000 Binary files a/examples/distributed-tracing-example/readme-resources/9-deploy-api.png and /dev/null differ diff --git a/examples/distributed-tracing-example/template.yaml b/examples/distributed-tracing-example/template.yaml index c75e294..075d984 100644 --- a/examples/distributed-tracing-example/template.yaml +++ b/examples/distributed-tracing-example/template.yaml @@ -11,6 +11,15 @@ Globals: Timeout: 20 Resources: + # Since the DTCallerFunction's definition depends on the ApiGatewayApiCallee, it needs to be separate from the ApiGatewayApiCaller, to avoid circular dependencies + ApiGatewayApiCallee: + Type: AWS::Serverless::Api + Properties: + StageName: testing + ApiGatewayApiCaller: + Type: AWS::Serverless::Api + Properties: + StageName: testing DTCalleeFunction: Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction Properties: @@ -18,10 +27,36 @@ Resources: Handler: com.example.DTCalleeFunction::handleRequest Runtime: java8 MemorySize: 512 + # SAM templates make it easy to bind a Lambda function to an API Gateway resource. Managing them together in a single template helps maintain consistency across the application. + Events: + CalleeApi: + Type: Api + Properties: + Path: /dt-callee + Method: get + RestApiId: + Ref: ApiGatewayApiCallee DTCallerFunction: - Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction + Type: AWS::Serverless::Function Properties: CodeUri: DTCallerFunction Handler: com.example.DTCallerFunction::handleRequest Runtime: java8 - MemorySize: 512 \ No newline at end of file + MemorySize: 512 + Environment: + Variables: + # This environment variable's value depends on the generated identifier for the ApiGatewayApiCallee resource. Tying together these dependencies is one of the strengths of SAM templates. + API_GATEWAY_PROXY_URL: !Sub https://${ApiGatewayApiCallee}.execute-api.${AWS::Region}.amazonaws.com/testing/dt-callee + Events: + CallerApi: + Type: Api + Properties: + Path: /dt-caller + Method: get + RestApiId: + Ref: ApiGatewayApiCaller +# Outputs print their value when the template is deployed. More importantly, the value can be imported and used in other templates. +Outputs: + CallerEndpoint: + Description: "New Relic DT example testing stage caller endpoint" + Value: !Sub https://${ApiGatewayApiCaller}.execute-api.${AWS::Region}.amazonaws.com/testing/dt-caller