Search code examples
terraformserverless-frameworkserverlessaws-serverless

Serverless Deploy to Different AWS Accounts


I have serverless project with bunch of terraform resource creation. I would like to deploy Lambda functions in one AWS account and as part of serverless deploy, it can create API Gateway endpoints (pointing to lambda functions).

I would like to API Gateway to be created in Another AWS Account. Is it possible do purely in serverless. If not what are the options ?


Solution

  • Try an EventBridge approach. You should be able to access functions securely, without creating complex dual-account ARNs, Policy Scripts and permissions:

    const AWS = require('aws-sdk');
    
    function notifyMarketingTeam(email) {
     const eventBridge = new AWS.EventBridge({key:XXXXX,secret:XXXX region: 'us-east-1' }); 
    
     return eventBridge.putEvents({
       Entries: [
         {
           EventBusName: 'marketing',
           Source: 'acme.newsletter.campaign',
           DetailType: 'UserSignUp',
           Detail: `{ "E-Mail": "${email}" }`,
       },
       ]
     }).promise()
    }