0
0

More than 3 years have passed since last update.

lambda × SNS クロスアカウント設定

Posted at

SNSアクセスポリシー

Image from Gyazo

lambda IAMロール

Image from Gyazo

lambda作成

Image from Gyazo

lambdaコード

Image from Gyazo

var aws = require('aws-sdk');

var sns = new aws.SNS({
   apiVersion: '2010-03-31',
   region: 'ap-northeast-1'
});

function timer(ms, name) {
  console.log(`name: ${name} start!`)
  return new Promise((resolve, reject) => {
    setTimeout(() => resolve(name), ms)
  })
}

exports.handler = async function(event, context) {
    console.log('publish start')
    await timer(1000, publish(event, context));

    function publish(event, context) {
        sns.publish({
            Message: 'Message',
            Subject: 'Message title ' ,
            TargetArn: 'arn:aws:sns:region:accountId:別アカウント' // 別アカウントSNSのArn 
            }, function(err, data) {
                if (err) {
                    console.log(err.stack);
                    return "failed publish".err.stack;
                }
                console.log('publish sent');
                console.log(data);
        });
    }
};

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0