Skip to content

docs: refresh SAM examples #1180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/lambda-functions/common/dynamodb-client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { DynamoDBClient, ScanCommand, GetItemCommand, PutItemCommand } from '@aws-sdk/client-dynamodb';

const dynamodbClientV3 = new DynamoDBClient({});
Expand Down
8 changes: 4 additions & 4 deletions examples/lambda-functions/get-all-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const getAllItemsHandler = async (event: APIGatewayProxyEvent, context: Context)
});

// Request a sample random uuid from a webservice
const res = await got("https://httpbin.org/uuid");
const res = await got('https://httpbin.org/uuid');
const uuid = JSON.parse(res.body).uuid;

// Logger: Append uuid to each log statement
Expand Down Expand Up @@ -116,8 +116,8 @@ const getAllItemsHandler = async (event: APIGatewayProxyEvent, context: Context)
// Wrap the handler with middy
export const handler = middy(getAllItemsHandler)
// Use the middleware by passing the Metrics instance as a parameter
.use(logMetrics(metrics))
.use(logMetrics(metrics))
// Use the middleware by passing the Logger instance as a parameter
.use(injectLambdaContext(logger, { logEvent: true }))
.use(injectLambdaContext(logger, { logEvent: true }))
// Use the middleware by passing the Tracer instance as a parameter
.use(captureLambdaHandler(tracer));
.use(captureLambdaHandler(tracer));
16 changes: 9 additions & 7 deletions examples/lambda-functions/get-by-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ const tableName = process.env.SAMPLE_TABLE;

class Lambda implements LambdaInterface {

@tracer.captureMethod()
public async getUuid(): Promise<string> {
// Request a sample random uuid from a webservice
const res = await got('https://httpbin.org/uuid');

return JSON.parse(res.body).uuid;
}

@tracer.captureLambdaHandler()
@logger.injectLambdaContext({ logEvent: true })
@metrics.logMetrics()
Expand Down Expand Up @@ -93,7 +101,7 @@ class Lambda implements LambdaInterface {
{
S: event.pathParameters.id
}
},
},
}));
const item = data.Item;
response = {
Expand Down Expand Up @@ -121,12 +129,6 @@ class Lambda implements LambdaInterface {
return response;
}

@tracer.captureMethod()
public async getUuid() {
// Request a sample random uuid from a webservice
const res = await got("https://httpbin.org/uuid");
return JSON.parse(res.body).uuid;
}
}

const handlerClass = new Lambda();
Expand Down
4 changes: 2 additions & 2 deletions examples/lambda-functions/put-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const handler = async (event: APIGatewayProxyEvent, context: Context): Pr
});

// Request a sample random uuid from a webservice
const res = await got("https://httpbin.org/uuid");
const res = await got('https://httpbin.org/uuid');
const uuid = JSON.parse(res.body).uuid;

// Logger: Append uuid to each log statement
Expand Down Expand Up @@ -88,7 +88,7 @@ export const handler = async (event: APIGatewayProxyEvent, context: Context): Pr

await docClient.send(new PutItemCommand({
TableName: tableName,
Item: { id: {S: id}, name: {S: name} }
Item: { id: { S: id }, name: { S: name } }
}));
response = {
statusCode: 200,
Expand Down