Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified javascript/example_code/lambda/tutorial/slotassets.zip
Binary file not shown.
4 changes: 4 additions & 0 deletions javascript/example_code/lambda/tutorial/slotassets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
MyLambdaApp/main.js
index.zip
index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@charset "UTF-8";
/* CSS Document */

#appframe {
background-image: url(resources/slotmachine.jpg);
background-repeat: no-repeat;
background-origin:content-box;
position:relative;
min-height: 1080px;
width: 1000px;
}

#slot_L {
position: absolute;
left: 354px;
top: 272px;
min-height: 199px;
width: 80px;
}

#slot_M {
position: absolute;
left: 482px;
top: 272px;
min-height: 199px;
width: 80px;
}

#slot_R {
position: absolute;
left: 606px;
top: 272px;
min-height: 199px;
width: 80px;
}

#slot_handle {
position: absolute;
left: 860px;
top: 10px;
min-height: 943px;
width: 114px;
}

#winner_light {
position: absolute;
left: 318px;
top: 540px;
min-height: 48px;
width: 247px;
visibility:hidden;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Card Slots</title>
<link href="cardslots.css" rel="stylesheet" type="text/css">

</head>

<body>
<div id="appframe">

<img id="slot_L" src="resources/hart_q.png" height="199" width="80" alt="slot wheel 1"/>
<img id="slot_M" src="resources/hart_q.png" height="199" width="80" alt="slot wheel 2"/>
<img id="slot_R" src="resources/hart_q.png" height="199" width="80" alt="slot wheel 3"/>
<img id="slot_handle" src="resources/lever-up.png" height="943" width="114"/>
<img id="winner_light" src="resources/winner.png" height="48" width="247" alt="winner indicator"/>

</div>
<script type="text/javascript" src="main.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const { CognitoIdentityClient } = require("@aws-sdk/client-cognito-identity");
const { fromCognitoIdentityPool } = require("@aws-sdk/credential-provider-cognito-identity");
const { LambdaClient, InvokeCommand } = require("@aws-sdk/client-lambda");

// Configure AWS SDK for JavaScript & set region and credentials
// Initialize the Amazon Cognito credentials provider
const region = "us-west-2";
const lambda = new LambdaClient({
region: region,
credentials: fromCognitoIdentityPool({
client: new CognitoIdentityClient({region}),
identityPoolId: "IDENTITY_POOL_ID"
})
});

/* CLIENT UI CODE */
// Application global variables
var isSpinning = false;
const pullHandle = () => {
if (isSpinning == false) {
// Show the handle pulled down
slot_handle.src = "resources/lever-dn.png";
}
}

const slot_L = document.querySelector("#slot_L");
const slot_M = document.querySelector("#slot_M");
const slot_R = document.querySelector("#slot_R");
const winner_light = document.querySelector("#winner_light");

const initiatePull = () => {
// Show the handle flipping back up
slot_handle.src = "resources/lever-up.png";
// Set all three wheels "spinning"
slot_L.src = "resources/slotpullanimation.gif";
slot_M.src = "resources/slotpullanimation.gif";
slot_R.src = "resources/slotpullanimation.gif";
winner_light.style.visibility = "hidden";

// Set app status to spinning
isSpinning = true;
// Call the Lambda function to collect the spin results
lambda.send(new InvokeCommand({
FunctionName : "slotpull",
InvocationType : "RequestResponse",
LogType : "None"
}), function(err, data) {
if (err) {
prompt(err);
} else {
pullResults = JSON.parse(
//parse Uint8Array payload to string
new TextDecoder("utf-8").decode(data.Payload)
);
displayPull();
}
});
}

const displayPull = () => {
isSpinning = false;
if (pullResults.isWinner) {
winner_light.style.visibility = "visible";
}
slot_L.src = `resources/${pullResults.leftWheelImage.file.S}`;
slot_M.src = `resources/${pullResults.middleWheelImage.file.S}`;
slot_R.src = `resources/${pullResults.rightWheelImage.file.S}`;
};

const slotHandle = document.querySelector("#slot_handle");
slotHandle.onmousedown = pullHandle;
slotHandle.onmouseup = initiatePull;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2010-2017 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.
*/

// Load the DynamoDB client
const { DynamoDBClient, CreateTableCommand } = require('@aws-sdk/client-dynamodb');
// Instantiate a DynamoDB client
const ddb = new DynamoDBClient({region: 'us-west-2'});
// Define the table schema
var tableParams = {
AttributeDefinitions: [
{
AttributeName: 'slotPosition',
AttributeType: 'N'
}
],
KeySchema: [
{
AttributeName: 'slotPosition',
KeyType: 'HASH'
}
],
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5
},
//TODO: change back to TABLE_NAME
TableName: 'v3-lambda-tutorial-table',
StreamSpecification: {
StreamEnabled: false
}
};

async function run() {
try {
const data = await ddb.send(new CreateTableCommand(tableParams));
console.log('Success', data);
} catch(err) {
console.log('Error', err);
}
}

run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
Copyright 2010-2017 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.
*/


// Load the DynamoDB client
const { DynamoDBClient, PutItemCommand } = require('@aws-sdk/client-dynamodb');
// Instantiate a DynamoDB client
const ddb = new DynamoDBClient({region: 'us-west-2'});

const myTable = 'TABLE_NAME';

// Add the four spade results
async function run() {
let params = {
TableName: myTable,
Item: {'slotPosition' : {N: '0'}, 'imageFile' : {S: 'spad_a.png'}
}
};
await post(params);

params = {
TableName: myTable,
Item: {'slotPosition' : {N: '1'}, 'imageFile' : {S: 'spad_k.png'}
}
};
await post(params);

params = {
TableName: myTable,
Item: {'slotPosition' : {N: '2'}, 'imageFile' : {S: 'spad_q.png'}
}
};
await post(params);

params = {
TableName: myTable,
Item: {'slotPosition' : {N: '3'}, 'imageFile' : {S: 'spad_j.png'}
}
};
await post(params);

// Add the four heart results
params = {
TableName: myTable,
Item: {'slotPosition' : {N: '4'}, 'imageFile' : {S: 'hart_a.png'}
}
};
await post(params);

params = {
TableName: myTable,
Item: {'slotPosition' : {N: '5'}, 'imageFile' : {S: 'hart_k.png'}
}
};
await post(params);

params = {
TableName: myTable,
Item: {'slotPosition' : {N: '6'}, 'imageFile' : {S: 'hart_q.png'}
}
};
await post(params);

params = {
TableName: myTable,
Item: {'slotPosition' : {N: '7'}, 'imageFile' : {S: 'hart_j.png'}
}
};
await post(params);

// Add the four diamonds results
params = {
TableName: myTable,
Item: {'slotPosition' : {N: '8'}, 'imageFile' : {S: 'diam_a.png'}
}
};
await post(params);

params = {
TableName: myTable,
Item: {'slotPosition' : {N: '9'}, 'imageFile' : {S: 'diam_k.png'}
}
};
await post(params);

params = {
TableName: myTable,
Item: {'slotPosition' : {N: '10'}, 'imageFile' : {S: 'diam_q.png'}
}
};
await post(params);

params = {
TableName: myTable,
Item: {'slotPosition' : {N: '11'}, 'imageFile' : {S: 'diam_j.png'}
}
};
await post(params);

params = {
TableName: myTable,
Item: {'slotPosition' : {N: '12'}, 'imageFile' : {S: 'club_a.png'}
}
};
await post(params);

params = {
TableName: myTable,
Item: {'slotPosition' : {N: '13'}, 'imageFile' : {S: 'club_k.png'}
}
};
await post(params);

params = {
TableName: myTable,
Item: {'slotPosition' : {N: '14'}, 'imageFile' : {S: 'club_q.png'}
}
};
await post(params);

params = {
TableName: myTable,
Item: {'slotPosition' : {N: '15'}, 'imageFile' : {S: 'club_j.png'}
}
};
await post(params);
}

run();

async function post (params) {
try {
const data = await ddb.send(new PutItemCommand(params));
console.log("Success", data);
} catch(err) {
console.log("Error", err);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2010-2017 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.
*/

// Load the Lambda client
const { LambdaClient, CreateFunctionCommand } = require('@aws-sdk/client-lambda');
// Instantiate a Lambda client
const lambda = new LambdaClient({region: 'us-west-2'});

var params = {
Code: { /* required */
S3Bucket: 'BUCKET_NAME',
S3Key: 'ZIP_FILE_NAME'
},
FunctionName: 'slotpull', /* required */
Handler: 'index.handler', /* required */
Role: 'arn:aws:iam::650138640062:role/v3-lambda-tutorial-lambda-role', /* required */
Runtime: 'nodejs12.x', /* required */
Description: 'Slot machine game results generator',
};
lambda.send(new CreateFunctionCommand(params)).then(
data => { console.log(data) }, // successful response
err => {console.log(err)} // an error occurred
);
Loading