mirror of
https://github.com/ivabus/www
synced 2024-11-10 12:05:16 +03:00
try write
This commit is contained in:
parent
d613daac08
commit
7b85af805c
|
@ -11,7 +11,8 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@middy/core": "^3.4.0",
|
||||
"@middy/http-json-body-parser": "^3.4.0"
|
||||
"@middy/http-json-body-parser": "^3.4.0",
|
||||
"aws-sdk": "^2.1234.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@serverless/typescript": "^3.0.0",
|
||||
|
|
|
@ -4,11 +4,42 @@ import { middyfy } from '@libs/lambda';
|
|||
|
||||
import schema from './schema';
|
||||
|
||||
import AWS from 'aws-sdk/global';
|
||||
import S3 from 'aws-sdk/clients/s3';
|
||||
const s3 = new S3();
|
||||
|
||||
const hello: ValidatedEventAPIGatewayProxyEvent<typeof schema> = async (event) => {
|
||||
await writeData();
|
||||
return formatJSONResponse({
|
||||
message: `Hello ${event.body.name}, welcome to the exciting Serverless world!`,
|
||||
event,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const writeData = async () => {
|
||||
try {
|
||||
|
||||
const obj = {
|
||||
firstname: "Navjot",
|
||||
lastname: "Dhanawat"
|
||||
};
|
||||
|
||||
const buf = Buffer.from(JSON.stringify(obj));
|
||||
|
||||
const data = {
|
||||
Bucket: 'mockdist.tea.xyz',
|
||||
Key: 'packages.json',
|
||||
Body: buf,
|
||||
ContentEncoding: 'base64',
|
||||
ContentType: 'application/json',
|
||||
ACL: 'public-read'
|
||||
};
|
||||
|
||||
await s3.upload(data);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
export const main = middyfy(hello);
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
"removeComments": true,
|
||||
"sourceMap": true,
|
||||
"target": "ES2020",
|
||||
"outDir": "lib"
|
||||
"outDir": "lib",
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": ["src/**/*.ts", "serverless.ts"],
|
||||
"exclude": [
|
||||
|
|
|
@ -457,6 +457,22 @@ aws-sdk@^2.1231.0:
|
|||
uuid "8.0.0"
|
||||
xml2js "0.4.19"
|
||||
|
||||
aws-sdk@^2.1234.0:
|
||||
version "2.1234.0"
|
||||
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.1234.0.tgz#2a3883295c77c789f8a95fbadc0fd37a998ac026"
|
||||
integrity sha512-QFuSeYM8DPiXytspLnWToy4MWJPGYFCgAy4hi+lRd6ueJtCey7MBIgFNHW814uAJzKUDEdJUJZPvDZvtLM1d/Q==
|
||||
dependencies:
|
||||
buffer "4.9.2"
|
||||
events "1.1.1"
|
||||
ieee754 "1.1.13"
|
||||
jmespath "0.16.0"
|
||||
querystring "0.2.0"
|
||||
sax "1.2.1"
|
||||
url "0.10.3"
|
||||
util "^0.12.4"
|
||||
uuid "8.0.0"
|
||||
xml2js "0.4.19"
|
||||
|
||||
axios@^0.21.1:
|
||||
version "0.21.4"
|
||||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575"
|
||||
|
|
Loading…
Reference in a new issue