Last active
June 30, 2021 19:27
-
-
Save fredericbarthelet/22998c2c212b9a58fcaea56de4a6d211 to your computer and use it in GitHub Desktop.
lambda with dynamo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { DynamoDB } from 'aws-sdk'; | |
export default { | |
handler:'create.main', | |
environment: { | |
TABLE_NAME: { | |
Ref: 'MyTable' | |
} | |
}, | |
events: [ | |
{ httpApi: 'POST /new'} | |
] | |
} | |
const DocumentClient = new DynamoDB.DocumentClient(); | |
const main = async (event) => { | |
await DocumentClient.putItem({ | |
TableName: process.env.TABLE_NAME, | |
Item: JSON.parse(event.body) | |
}).promise(); | |
return 'success'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import create from './create'; | |
const serverlessConfiguration: Serverless = { | |
service: 'myServerlessService', | |
provider: { | |
name: 'aws', | |
runtime: 'nodejs12.x' | |
}, | |
functions: { | |
create | |
}, | |
resources: { | |
Resources: { | |
MyTable: { | |
Type: 'AWS::DynamoDB::Table', | |
Properties: { | |
AttributeDefinitions: [ | |
{ AttributeName: 'PK', AttributeType: 'S' }, | |
{ AttributeName: 'SK', AttributeType: 'S' } | |
], | |
KeySchema: [ | |
{ AttributeName: 'PK', KeyType: 'HASH' }, | |
{ AttributeName: 'SK', KeyType: 'RANGE' } | |
], | |
BillingMode: 'PAY_PER_REQUEST' | |
} | |
} | |
} | |
} | |
}; | |
module.exports = serverlessConfiguration; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment