Skip to content

Commit 1b56d84

Browse files
Ishmeal BaawuahIshmeal Baawuah
Ishmeal Baawuah
authored and
Ishmeal Baawuah
committed
Revert "forcing the custom init function to run on each push"
This reverts commit caacc88.
1 parent caacc88 commit 1b56d84

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

src/services/database/handlers/seeddatabase.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
import { send, SUCCESS, FAILED } from "cfn-response-async";
22
import { putItem } from "../../../libs";
3-
import axios from "axios";
3+
import * as items from "../items.json";
44

55
exports.handler = async function (event: any, context: any) {
66
console.log("Request:", JSON.stringify(event, undefined, 2));
77
const responseData = {};
88
let responseStatus: any = SUCCESS;
99
try {
10-
const url = "https://jsonplaceholder.typicode.com/posts";
11-
const response = await axios.get(url);
12-
const items = response.data.map((item: any) => ({
13-
PK: item.id,
14-
SK: item.title,
15-
body: item.body,
16-
}));
1710
for await (const item of items) {
18-
await putItem({
11+
putItem({
1912
tableName: event.ResourceProperties.DynamoTableName,
20-
item,
13+
item: { PK: item.recordId, SK: item.state },
2114
});
2215
}
2316
} catch (error) {

src/services/database/items.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[
2+
{
3+
"recordId": "67-tyuiop",
4+
"state": "CA"
5+
},
6+
{
7+
"recordId": "76-SeargentBrianwasHere",
8+
"state": "OH"
9+
},
10+
{
11+
"recordId": "96-kings",
12+
"state": "DE"
13+
},
14+
{
15+
"recordId": "45-dialect",
16+
"state": "UT"
17+
}
18+
]

src/services/database/serverless.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ custom:
4545
- production
4646
tableName: ${self:service}-${sls:stage}-table
4747

48+
parameters:
49+
fileHash:
50+
Type: String
51+
Default: ""
52+
4853
functions:
4954
seeddatabase:
5055
handler: handlers/seeddatabase.handler
@@ -76,4 +81,4 @@ resources:
7681
Fn::GetAtt: [SeeddatabaseLambdaFunction, "Arn"]
7782
DynamoTableName:
7883
Ref: Table
79-
forceUpdate: !Ref AWS::StackName-InitFunction-#{timestamp()}
84+
FILE_HASH: ${self:custom.fileHash}

0 commit comments

Comments
 (0)