Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 0 additions & 32 deletions csharp/my-widget-service/src/MyWidgetService/resources/widgets.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,8 @@
//snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.]
//snippet-comment:[This should be in the resources/ directory]
//snippet-comment:[and only works with my_widget_service.ts in the bin/ directory]
//snippet-comment:[and widget_service.ts in the lib/ directory.]
//snippet-sourceauthor:[Doug-AWS]
//snippet-sourcedescription:[Lambda function to handle GET, POST, and DELETE.]
//snippet-keyword:[CDK V0.24.1]
//snippet-keyword:[S3.deleteObject function]
//snippet-keyword:[S3.getObject function]
//snippet-keyword:[S3.listObjectsV2 function]
//snippet-keyword:[S3.putObject function]
//snippet-keyword:[JavaScript]
//snippet-service:[cdk]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[2019-2-8]
// Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// This file is licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.
//snippet-start:[cdk.typescript.widgets]
//snippet-start:[cdk.typescript.widgets.imports]
const AWS = require('aws-sdk');
const S3 = new AWS.S3();
//snippet-end:[cdk.typescript.widgets.imports]

const bucketName = process.env.BUCKET;

//snippet-start:[cdk.typescript.widgets.exports_main]
exports.main = async function(event, context) {
try {
var method = event.httpMethod;
Expand Down Expand Up @@ -134,5 +104,3 @@ exports.main = async function(event, context) {
}
}
}
//snippet-end:[cdk.typescript.widgets.exports_main]
//snippet-end:[cdk.typescript.widgets]
32 changes: 0 additions & 32 deletions java/my-widget-service/resources/widgets.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,8 @@
//snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.]
//snippet-comment:[This should be in the resources/ directory]
//snippet-comment:[and only works with my_widget_service.ts in the bin/ directory]
//snippet-comment:[and widget_service.ts in the lib/ directory.]
//snippet-sourceauthor:[Doug-AWS]
//snippet-sourcedescription:[Lambda function to handle GET, POST, and DELETE.]
//snippet-keyword:[CDK V0.24.1]
//snippet-keyword:[S3.deleteObject function]
//snippet-keyword:[S3.getObject function]
//snippet-keyword:[S3.listObjectsV2 function]
//snippet-keyword:[S3.putObject function]
//snippet-keyword:[JavaScript]
//snippet-service:[cdk]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[2019-2-8]
// Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// This file is licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.
//snippet-start:[cdk.typescript.widgets]
//snippet-start:[cdk.typescript.widgets.imports]
const AWS = require('aws-sdk');
const S3 = new AWS.S3();
//snippet-end:[cdk.typescript.widgets.imports]

const bucketName = process.env.BUCKET;

//snippet-start:[cdk.typescript.widgets.exports_main]
exports.main = async function(event, context) {
try {
var method = event.httpMethod;
Expand Down Expand Up @@ -134,5 +104,3 @@ exports.main = async function(event, context) {
}
}
}
//snippet-end:[cdk.typescript.widgets.exports_main]
//snippet-end:[cdk.typescript.widgets]
2 changes: 1 addition & 1 deletion typescript/api-cors-lambda-crud-dynamodb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ApiLambdaCrudDynamoDBStack extends Stack {
PRIMARY_KEY: 'itemId',
TABLE_NAME: dynamoTable.tableName,
},
runtime: Runtime.NODEJS_14_X,
runtime: Runtime.NODEJS_20_X,
}

// Create a Lambda function for each of the CRUD operations
Expand Down
7 changes: 4 additions & 3 deletions typescript/api-cors-lambda-crud-dynamodb/lambdas/create.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as AWS from 'aws-sdk';
import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
import { DynamoDB } from '@aws-sdk/client-dynamodb';
import { v4 as uuidv4 } from 'uuid';

const TABLE_NAME = process.env.TABLE_NAME || '';
const PRIMARY_KEY = process.env.PRIMARY_KEY || '';

const db = new AWS.DynamoDB.DocumentClient();
const db = DynamoDBDocument.from(new DynamoDB());

const RESERVED_RESPONSE = `Error: You're using AWS reserved keywords as attributes`,
DYNAMODB_EXECUTION_ERROR = `Error: Execution update, caused a Dynamodb error, please take a look at your CloudWatch Logs.`;
Expand All @@ -22,7 +23,7 @@ export const handler = async (event: any = {}): Promise<any> => {
};

try {
await db.put(params).promise();
await db.put(params);
return { statusCode: 201, body: '' };
} catch (dbError) {
const errorResponse = dbError.code === 'ValidationException' && dbError.message.includes('reserved keyword') ?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as AWS from 'aws-sdk';
import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
import { DynamoDB } from '@aws-sdk/client-dynamodb';

const TABLE_NAME = process.env.TABLE_NAME || '';
const PRIMARY_KEY = process.env.PRIMARY_KEY || '';

const db = new AWS.DynamoDB.DocumentClient();
const db = DynamoDBDocument.from(new DynamoDB());

export const handler = async (event: any = {}): Promise<any> => {

Expand All @@ -20,7 +21,7 @@ export const handler = async (event: any = {}): Promise<any> => {
};

try {
await db.delete(params).promise();
await db.delete(params);
return { statusCode: 200, body: '' };
} catch (dbError) {
return { statusCode: 500, body: JSON.stringify(dbError) };
Expand Down
7 changes: 4 additions & 3 deletions typescript/api-cors-lambda-crud-dynamodb/lambdas/get-all.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as AWS from 'aws-sdk';
import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
import { DynamoDB } from '@aws-sdk/client-dynamodb';

const TABLE_NAME = process.env.TABLE_NAME || '';

const db = new AWS.DynamoDB.DocumentClient();
const db = DynamoDBDocument.from(new DynamoDB());

export const handler = async (): Promise<any> => {

Expand All @@ -11,7 +12,7 @@ export const handler = async (): Promise<any> => {
};

try {
const response = await db.scan(params).promise();
const response = await db.scan(params);
return { statusCode: 200, body: JSON.stringify(response.Items) };
} catch (dbError) {
return { statusCode: 500, body: JSON.stringify(dbError) };
Expand Down
7 changes: 4 additions & 3 deletions typescript/api-cors-lambda-crud-dynamodb/lambdas/get-one.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as AWS from 'aws-sdk';
import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
import { DynamoDB } from '@aws-sdk/client-dynamodb';

const TABLE_NAME = process.env.TABLE_NAME || '';
const PRIMARY_KEY = process.env.PRIMARY_KEY || '';

const db = new AWS.DynamoDB.DocumentClient();
const db = DynamoDBDocument.from(new DynamoDB());

export const handler = async (event: any = {}): Promise<any> => {

Expand All @@ -20,7 +21,7 @@ export const handler = async (event: any = {}): Promise<any> => {
};

try {
const response = await db.get(params).promise();
const response = await db.get(params);
if (response.Item) {
return { statusCode: 200, body: JSON.stringify(response.Item) };
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"@types/uuid": "*"
},
"dependencies": {
"aws-sdk": "*",
"@aws-sdk/client-dynamodb": "^3.538.0",
"@aws-sdk/lib-dynamodb": "^3.538.0",
"uuid": "*"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as AWS from 'aws-sdk';
import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
import { DynamoDB } from '@aws-sdk/client-dynamodb';

const TABLE_NAME = process.env.TABLE_NAME || '';
const PRIMARY_KEY = process.env.PRIMARY_KEY || '';
Expand All @@ -7,7 +8,7 @@ const PRIMARY_KEY = process.env.PRIMARY_KEY || '';
const RESERVED_RESPONSE = `Error: You're using AWS reserved keywords as attributes`,
DYNAMODB_EXECUTION_ERROR = `Error: Execution update, caused a Dynamodb error, please take a look at your CloudWatch Logs.`;

const db = new AWS.DynamoDB.DocumentClient();
const db = DynamoDBDocument.from(new DynamoDB());

export const handler = async (event: any = {}): Promise<any> => {

Expand Down Expand Up @@ -44,7 +45,7 @@ export const handler = async (event: any = {}): Promise<any> => {
});

try {
await db.update(params).promise();
await db.update(params);
return { statusCode: 204, body: '' };
} catch (dbError) {
const errorResponse = dbError.code === 'ValidationException' && dbError.message.includes('reserved keyword') ?
Expand Down
2 changes: 1 addition & 1 deletion typescript/appsync-graphql-eventbridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class AppSyncCdkStack extends cdk.Stack {
"exports.handler = (event, context) => { console.log(event); context.succeed(event); }"
),
handler: "index.handler",
runtime: lambda.Runtime.NODEJS_16_X
runtime: lambda.Runtime.NODEJS_LATEST
});

const rule = new Rule(this, "AppSyncEventBridgeRle", {
Expand Down
4 changes: 2 additions & 2 deletions typescript/lambda-layer/lib/lambda-layer-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export class LambdaLayerStack extends cdk.Stack {
const layer = new lambda.LayerVersion(this, 'HelperLayer', {
code: lambda.Code.fromAsset('resources/layers/helper'),
description: 'Common helper utility',
compatibleRuntimes: [lambda.Runtime.NODEJS_14_X],
compatibleRuntimes: [lambda.Runtime.NODEJS_LATEST],
removalPolicy: cdk.RemovalPolicy.DESTROY
});

const fn = new lambda.Function(this, 'LambdaFunction', {
runtime: lambda.Runtime.NODEJS_14_X,
runtime: lambda.Runtime.NODEJS_LATEST,
code: lambda.Code.fromAsset('resources/lambda'),
handler: 'index.handler',
layers: [layer]
Expand Down
15 changes: 9 additions & 6 deletions typescript/my-widget-service/resources/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
// language governing permissions and limitations under the License.
//snippet-start:[cdk.typescript.widgets]
//snippet-start:[cdk.typescript.widgets.imports]
const AWS = require('aws-sdk');
const S3 = new AWS.S3();


const { S3 } = require("@aws-sdk/client-s3");

const S3 = new S3();
//snippet-end:[cdk.typescript.widgets.imports]

const bucketName = process.env.BUCKET;
Expand All @@ -42,7 +45,7 @@ exports.main = async function(event, context) {
if (method === "GET") {
// GET / to get the names of all widgets
if (event.path === "/") {
const data = await S3.listObjectsV2({ Bucket: bucketName }).promise();
const data = await S3.listObjectsV2({ Bucket: bucketName });
var body = {
widgets: data.Contents.map(function(e) { return e.Key })
};
Expand All @@ -55,7 +58,7 @@ exports.main = async function(event, context) {

if (widgetName) {
// GET /name to get info on widget name
const data = await S3.getObject({ Bucket: bucketName, Key: widgetName}).promise();
const data = await S3.getObject({ Bucket: bucketName, Key: widgetName});
var body = data.Body.toString('utf-8');

return {
Expand Down Expand Up @@ -88,7 +91,7 @@ exports.main = async function(event, context) {
Key: widgetName,
Body: base64data,
ContentType: 'application/json'
}).promise();
});

return {
statusCode: 200,
Expand All @@ -110,7 +113,7 @@ exports.main = async function(event, context) {

await S3.deleteObject({
Bucket: bucketName, Key: widgetName
}).promise();
});

return {
statusCode: 200,
Expand Down
2 changes: 1 addition & 1 deletion typescript/my-widget-service/widget_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class WidgetService extends Construct {
});

const handler = new lambda.Function(this, "WidgetHandler", {
runtime: lambda.Runtime.NODEJS_16_X, // So we can use async in widget.js
runtime: lambda.Runtime.NODEJS_20_X, // So we can use async in widget.js
code: lambda.AssetCode.fromAsset("resources"),
handler: "widgets.main",
environment: {
Expand Down
13 changes: 7 additions & 6 deletions typescript/rekognition-lambda-s3-trigger/lambda/rekfunction.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as AWS from 'aws-sdk';
import { DynamoDB } from '@aws-sdk/client-dynamodb';
import { DetectLabelsCommandInput, Rekognition } from '@aws-sdk/client-rekognition';

const client = new AWS.Rekognition();
const client = new Rekognition();
export const handler = async (event: any = {}): Promise<any> => {
const key = event.Records[0].s3.object.key
console.log(key);

const params: AWS.Rekognition.DetectLabelsRequest = {
const params: DetectLabelsCommandInput = {
Image: {
S3Object: {
Bucket: process.env.BUCKET_NAME,
Expand All @@ -16,13 +17,13 @@ export const handler = async (event: any = {}): Promise<any> => {
MinConfidence: 70
};

const response = await client.detectLabels(params).promise();
const response = await client.detectLabels(params);
const labels = response.Labels || [];
console.log(labels.map(i => i.Name).toString());

// Write to DDB
const tableName = process.env.TABLE_NAME || "";
const dynamodb = new AWS.DynamoDB();
const dynamodb = new DynamoDB();

const dynamodbParams = {
TableName: tableName,
Expand All @@ -34,7 +35,7 @@ export const handler = async (event: any = {}): Promise<any> => {
};

try {
await dynamodb.putItem(dynamodbParams).promise();
await dynamodb.putItem(dynamodbParams);
}
catch(err) {
console.log(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class RekognitionLambdaS3TriggerStack extends cdk.Stack {
// create Lambda function
const lambdaFunction = new lambda.Function(this, 'RekFunction', {
handler: 'rekfunction.handler',
runtime: lambda.Runtime.NODEJS_14_X,
runtime: lambda.Runtime.NODEJS_20_X,
code: lambda.Code.fromAsset(path.join(__dirname, '../lambda')),
environment: {
'BUCKET_NAME': bucket.bucketName,
Expand Down
7 changes: 4 additions & 3 deletions typescript/rekognition-lambda-s3-trigger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
"typescript": "~5.1.6"
},
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.538.0",
"@aws-sdk/client-rekognition": "^3.535.0",
"aws-cdk-lib": "*",
"aws-sdk": "^2.1062.0",
"source-map-support": "^0.5.16",
"constructs": "*"
"constructs": "*",
"source-map-support": "^0.5.16"
}
}
3 changes: 2 additions & 1 deletion typescript/rekognition-lambda-s3-trigger/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"target": "ES2022",
"module": "commonjs",
"lib": [
"ES2022"
"ES2022",
"dom"
],
"declaration": true,
"strict": true,
Expand Down
2 changes: 1 addition & 1 deletion typescript/s3-object-lambda/lib/s3-object-lambda-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class S3ObjectLambdaStack extends Stack {

// lambda to process our objects during retrieval
const retrieveTransformedObjectLambda = new lambda.Function(this, 'retrieveTransformedObjectLambda', {
runtime: lambda.Runtime.NODEJS_14_X,
runtime: lambda.Runtime.NODEJS_20_X,
handler: 'index.handler',
code: lambda.Code.fromAsset('resources/retrieve-transformed-object-lambda')
}
Expand Down
2 changes: 1 addition & 1 deletion typescript/s3-object-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"typescript": "~5.1.6"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.537.0",
"aws-cdk-lib": "^2.0.0",
"aws-sdk": "^2.1281.0",
"constructs": "^10.1.190",
"source-map-support": "^0.5.21"
}
Expand Down
Loading