AMAZON SNS(1)Serverless Lambda Send Message to SNS

AMAZON SNS(1)Serverless Lambda Send Message to SNS

I will need AWS-SDK to send message to SNS
> npm install aws-sdk

It will put the dependency there
"dependencies": {
"aws-sdk": "^2.224.1"
}

I create a SNS Topic manually first, named meeting-clientapi-int-crud
I create a SQS named meeting-cssgateway-int-crud it will subscribe from that SNS

Try to Install webpack
> sudo npm install webpack-cli
> sudo npm install webpack

But I still get the information as follow:
> webpack --version
The CLI moved into a separate package: webpack-cli
Would you like to install webpack-cli? (That will run npm install -D webpack-cli) (yes/NO)
It needs to be installed alongside webpack to use the CLI

> sudo npm i -D webpack-cli
> sudo npm i -g webpack-cli

> webpack --version
4.5.0

The global webpack version is too latest
> webpack
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.entry should be one of these:
object { : non-empty string | [non-empty string] } | non-empty string | [non-empty string] | function
-> The entry point(s) of the compilation.
Details:
* configuration.entry should not be empty.
-> Multiple entry bundles are created. The key is the chunk name. The value can be a string or an array.
* configuration.entry should be a string.
-> An entry point without name. The string is resolved to a module which is loaded upon startup.
* configuration.entry should be an array:
[non-empty string]
* configuration.entry should be an instance of function
-> A Function returning an entry object, an entry string, an entry array or a promise to these things.
- configuration.module has an unknown property 'loaders'. These properties are valid:
object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, defaultRules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp?, strictExportPresence?, strictThisContextOnImports? }
-> Options affecting the normal modules (`NormalModuleFactory`).

I will roll the global one to webpack 3
> sudo npm uninstall -g webpack
> sudo npm uninstall -g webpack-cli

> sudo npm install -g webpack@^3.6.0

> webpack --version
3.11.0

Still do not know how to run the webpack here. Ignore right now, check it later. Make the SNS work first.
Handler function send message to the SNS, I get the information from SQS which subscribe from SNS

import { APIGatewayEvent, Callback, Context, Handler } from 'aws-lambda';
import * as AWS from 'aws-sdk';

export const hello: Handler = (event: APIGatewayEvent, context: Context, cb: Callback) => {

AWS.config.region = 'us-west-1';
let sns = new AWS.SNS();

let message = { name: "carl", send : "hello 1" };

sns.publish({
Message: JSON.stringify(message),
TargetArn: 'arn:aws:sns:us-west-1:xxxxxxxxx:meeting-clientapi-int-crud'
}, function(err, data) {
if (err) { console.log(err.stack); return; }
console.log('push sent');
console.log(data);
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless Webpack (Typescript) v1.0! Your function executed successfully!',
input: event,
}),
};

cb(null, response);
});

}


References:
https://forum.serverless.com/t/solved-publishing-to-created-sns-topic/1426
https://gist.github.com/jeremypruitt/ab70d78b815eae84e037
https://stackoverflow.com/questions/41712021/aws-sns-push-notification-using-node-js
https://gist.github.com/tmarshall/6149ed2475f964cda3f5
https://aws.amazon.com/sdk-for-node-js/

你可能感兴趣的:(Summary,serverless,webpack,json)