Skip to content

Commit

Permalink
fix: re-enable tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Mar 18, 2024
1 parent a94d469 commit 07e900c
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 13 deletions.
37 changes: 25 additions & 12 deletions cdk/WebhookReceiverStack.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import * as CDK from 'aws-cdk-lib'
import * as IAM from 'aws-cdk-lib/aws-iam'
import * as Lambda from 'aws-cdk-lib/aws-lambda'
import * as Logs from 'aws-cdk-lib/aws-logs'
import * as SQS from 'aws-cdk-lib/aws-sqs'
import {
App,
CfnOutput,
Duration,
aws_iam as IAM,
aws_lambda as Lambda,
aws_logs as Logs,
RemovalPolicy,
aws_sqs as SQS,
Stack,
} from 'aws-cdk-lib'
import { PackedLambda } from './packLambda.js'

/**
* This is the CloudFormation stack which contains the webhook receiver resources.
*/
export class WebhookReceiverStack extends CDK.Stack {
export class WebhookReceiverStack extends Stack {
public constructor(
parent: CDK.App,
parent: App,
id: string,
{
lambdaSource,
Expand All @@ -23,18 +29,25 @@ export class WebhookReceiverStack extends CDK.Stack {
// This queue will store all the requests made to the API Gateway
const queue = new SQS.Queue(this, 'queue', {
fifo: true,
visibilityTimeout: CDK.Duration.seconds(5),
visibilityTimeout: Duration.seconds(5),
queueName: `${id}.fifo`,
})

// This lambda will publish all requests made to the API Gateway in the queue
const lambda = new Lambda.Function(this, 'Lambda', {
description: 'Publishes webhook requests into SQS',
code: Lambda.Code.fromAsset(lambdaSource.lambdaZipFile),
layers: [
Lambda.LayerVersion.fromLayerVersionArn(
this,
'powertool-layer',
`arn:aws:lambda:${Stack.of(this).region}:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:3`,
),
],
handler: lambdaSource.handler,
runtime: Lambda.Runtime.NODEJS_20_X,
architecture: Lambda.Architecture.ARM_64,
timeout: CDK.Duration.seconds(15),
timeout: Duration.seconds(15),
initialPolicy: [
new IAM.PolicyStatement({
resources: ['arn:aws:logs:*:*:*'],
Expand All @@ -56,7 +69,7 @@ export class WebhookReceiverStack extends CDK.Stack {

// Create the log group here, so we can control the retention
new Logs.LogGroup(this, `LambdaLogGroup`, {
removalPolicy: CDK.RemovalPolicy.DESTROY,
removalPolicy: RemovalPolicy.DESTROY,
logGroupName: `/cdk/lambda/${lambda.functionName}`,
retention: Logs.RetentionDays.ONE_DAY,
})
Expand All @@ -66,11 +79,11 @@ export class WebhookReceiverStack extends CDK.Stack {
})

// Export these so the test runner can use them
new CDK.CfnOutput(this, 'ApiURL', {
new CfnOutput(this, 'ApiURL', {
value: fnUrl.url,
exportName: `${this.stackName}:ApiURL`,
})
new CDK.CfnOutput(this, 'QueueURL', {
new CfnOutput(this, 'QueueURL', {
value: queue.queueUrl,
exportName: `${this.stackName}:QueueURL`,
})
Expand Down
4 changes: 3 additions & 1 deletion lambda/webhookReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
APIGatewayProxyEventV2WithRequestContext,
APIGatewayProxyResultV2,
} from 'aws-lambda'
import { Tracer } from '@aws-lambda-powertools/tracer'

const sqs = new SQSClient({})
const tracer = new Tracer({})
const sqs = tracer.captureAWSv3Client(new SQSClient({}))

export const handler = async (
event: APIGatewayProxyEventV2WithRequestContext<APIGatewayEventRequestContextV2>,
Expand Down
113 changes: 113 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"homepage": "https://github.com/NordicSemiconductor/cloud-bdd-markdown-e2e-example-aws-js#readme",
"devDependencies": {
"@aws-lambda-powertools/tracer": "2.0.3",
"@aws-sdk/client-cloudformation": "3.535.0",
"@aws-sdk/client-sqs": "3.535.0",
"@aws-sdk/client-xray": "3.535.0",
Expand Down

0 comments on commit 07e900c

Please sign in to comment.