Cross Account Deployment of Step Functions with Lambda Invoke Using Cloudformation and Codepipeline with Encrypted Bucket
Tags: awscloudformation, awscodepipeline, awsstepfunctions, awss3
Published: 2022-07-10 19:00:31

“ I have checked the documents of AWS to deploy step functions with lambda invoke across accounts using cloudformation and codepipeline with encrypted buckets . Issue in creation of all stacks using cloudformation in terms of access roles and policies. And creating template.yaml file for step function config and json template for lambda invoke arn. Issue is resolved by adding permissions in IAM roles and adding function arn or function name to invoke lambda in json. The Pricing is based on services usage.”

A keyword define "**Devtron**" play an important role in sorting the complexity of DevOps, AppOps and Kubernetes. Also "**GitHub**" helps to integrate and automate. Both Devtron and GitHub is an open source one.

In this post, you will experience the deployment step functions across accounts using cloudformation and codepipeline. Here I have created a codepipeline from cloudformation with artifacts to be stored in s3 bucket. And once the pipeline triggers, json content and config of step function will be deployed in a QA account with lambda invoke.

#Prerequisites
You’ll need an Amazon SNS for this post. [Getting started with amazon SNS](https://aws.amazon.com/sns/getting-started/) provides instructions on how to create a topic and subscription.
You’ll need an AWS Lambda for this post. [Getting started with aws Lambda](https://aws.amazon.com/lambda/getting-started/) provides instructions on how to create a lambda function. For this blog, I assume that I have an sns topic with confirmed subscription and a lambda function.

#Architecture Overview
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zcyb65ttxbwu3j1326xw.png)
The architecture diagram shows the overall deployment architecture with data flow, two aws account, code commit, code build, code deploy, code pipeline, s3, sns, cloudformation, lambda, kms, step function.

#Solution overview
The blog post consists of the following phases:
1. In Tool Account, Create of Cloudformation Stack for Service Configuration as S3, KMS, IAM and CodeCommit Repo
2. In QA Account, Create of Cloudformation Stack for Cross Account Access Role with Tool Account Number, KMS ARN and S3 Bucket Name
3. In Tool Account, Update of Service Stack for Config and Create of Cloudformation Stack for Pipeline Creation
4. Testing of Flow for Step Function Deployment from CICD and Checking of Logs in Cloudwatch

I have a sns topic with confirmed subscription and a lambda function as below →
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s37l2p0dyxbl725pepts.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gtaxwbn5k51hdbeg3nh3.png)

##Phase 1: In Tool Account, Create of Cloudformation Stack for Service Configuration as S3, KMS, IAM and CodeCommit Repo  
1. Open the cloudformation console and create a stack with a preconfigured yaml template for service configuration. Give details as QA account number.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/91jkh14q4doa2n2uqt6e.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p6kmzp4zve892ef6o50y.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l941ns15uuph88gs2wkm.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6x3hofzib6tsg8i3hzg8.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i4rzptjrymcm1lis5g35.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/as6mk1nho1p6wbffok8m.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wvjiid9rqpd5zdlk3g76.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v7qqr365mnajej04oj9t.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ib9owflfz2c2k71gyu1d.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/obmwi2vdkpk4spbv0r6w.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8y5m0ch7uypqp3rw9ej1.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p50tsodn6r7ejeyn17rs.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u2qcjtdoqmkn9sedacxv.png)

##Phase 2: In QA Account, Create of Cloudformation Stack for Cross Account Access Role with Tool Account Number, KMS ARN and S3 Bucket Name
1. Open the cloudformation console and Create a stack for cross account access IAM role.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yeuw8i6wwoctsxefkrsf.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d19zyvlxog3lmgpjjc28.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n1jf5xysf14c5p0ie21c.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pbh5teth1a1w0dbd49aw.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/klweji47358ukzqnwy9r.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nwy6qwhy5qm8p9saj5ro.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nnrk4jw3u4s127qxnflc.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/20dviknoumgp4fg3ip6v.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5j98mlvk7sathflkjfr4.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z1oej2vb4c89ah95koh0.png)

##Phase 3: In Tool Account, Update of Service Stack for Config and Create of Cloudformation Stack for Pipeline Creation
1. Open the cloudformation console and update the prerequisite on accounts parameter value to true. Also create a stack for pipeline creation with different stages as source, build, deploy to QA. Also manually adding an approval stage with notification after the build stage.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/evb7fg9y4h2i8yujp5z2.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vidwvx4g3we1n9f4mu6r.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ipb2dnbxu9yea9kl9bwz.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r20e6b7w3iwk3hx3cyn8.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5q7w6d2kx57aczqyj0mv.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9a9uoj823d859wmv4r3g.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4wemrywrlt85vsbd6n1t.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qpurnafcd89v7ewtko7w.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lioti8ti463ka4imwall.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c964tedqa2ieyhps6s3h.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/62ps3mw7yoz2xl3ovyty.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6hao74b4xi807of1oorv.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ezc1fzz5zlymx0h9rhlv.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0abrdpmkm3e0osyvj7p5.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0b8bix62sk8i5ntjee4k.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tk77pefs2issdk6jb045.png)

##Phase 4: Testing of Flow for Step Function Deployment from CICD and Checking of Logs in Cloudwatch
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s1prfgmsl91dado0e34u.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fd2bg05iiascgv8yr2ni.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uiseyq5rahi83vm1oxsm.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jdtbbvc6qpzyj4w76y1d.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3lowo4o3rf0sdro0v6mf.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/azfdr4ynvt4a861qxgtm.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x9pxcrt8awbtpz2g2f3i.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/04ciug3gxlqr4o0z277o.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6i0g84jwf8iyrkm6i571.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x37g10g75b4t9c4331oi.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x3fnvzx7s55h4r914e1s.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5j9gufkxm54f3k8b2do5.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y72ng54vurh02jtpsgl2.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nmun3mbu92k28tfug934.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0u3gekwmoisc9fqh0zpl.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xhzpzow0ojukqmr6btk1.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qrtd2zjib43f3gl1rtrg.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9pa82c1a2uhipszmq36l.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m5tslcm23asbxdqyxlqm.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/83o1mnbz71yak2pbfgwa.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o5q27450yi34618d0od0.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qsuaa4s2le8ds1lkqx2o.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nglxat22tc6e9movvggt.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/exfoq695wy434sax3cx8.png)

#Clean-up
Delete CloudFormation Stack in Tool and QA Account, Cloudwatch Log Group, SNS and Lambda.

#Pricing
I review the pricing and estimated cost of this example. 

Cost of CloudWatch = $0.0

Cost of CodeBuild = $0.0

Cost of CodeCommit = $0.0

Cost of Lambda = $0.0

Cost of Key Management Service = $0.01

Cost of Simple Notification Service = $0.0

Cost of Simple Storage Service = $1.0

Cost of Step Functions = $0 for first 4,000 state transitions = $0.0

Total Cost = $(0.0 + 0.0 + 0.0 + 0.0 + 0.01 + 0.0 + 1.0 + 0.0) = $1.01

#Summary
In this post, I showed “how to deploy a cross account step functions with lambda invoke using cloudformation and codepipeline with encrypted bucket”.

For more details on AWS CodePipeline, Checkout Get started AWS CodePipeline, open the [AWS CodePipeline console](https://ap-south-1.console.aws.amazon.com/codesuite/codepipeline/pipelines?region=ap-south-1&pipelines-meta=eyJmIjp7InRleHQiOiIifSwicyI6eyJwcm9wZXJ0eSI6InVwZGF0ZWQiLCJkaXJlY3Rpb24iOi0xfSwibiI6MTAsImkiOjB9). To learn more, read the [AWS CodePipeline documentation](https://docs.aws.amazon.com/codepipeline/?id=docs_gateway). 

For more details on AWS CloudFormation, Checkout Get started AWS CloudFormation, open the [AWS CloudFormation console](https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/). To learn more, read the [AWS CloudFormation documentation](https://docs.aws.amazon.com/cloudformation/?id=docs_gateway).

For more details on AWS Step Functions, Checkout Get started AWS Step Functions, open the [AWS Step Functions console](https://us-east-1.console.aws.amazon.com/states/home?region=us-east-1#/homepage). To learn more, read the [AWS Step Functions documentation](https://docs.aws.amazon.com/step-functions/?id=docs_gateway).

For more details on **Devtron and GitHub**, Checkout Links:
[Devtron Website](https://devtron.ai/)
[GitHub Repo](https://github.com/devtron-labs/devtron)
[Join the Discord Community](https://discord.com/invite/jsRG5qx2gp)
[Follow on Twitter](https://twitter.com/DevtronL)
[Raise feature requests, suggest enhancements, report bugs](https://github.com/devtron-labs/devtron/issues)
[Read Devtron Blog](https://devtron.ai/blog/)

Lets quickly adopt and try it! And post the response using **#AdoptK8sWithDevtron** **#devtron**

The above blog is submitted as part of 'Devtron Blogathon 2022' - [https://devtron.ai/](https://devtron.ai/)
Check out Devtron's GitHub repo - [https://github.com/devtron-labs/devtron/](https://github.com/devtron-labs/devtron/) and give a ⭐ to show your love & support.
Follow Devtron on LinkedIn - [https://www.linkedin.com/company/devtron-labs/](https://www.linkedin.com/company/devtron-labs/) and Twitter - [https://twitter.com/DevtronL/](https://twitter.com/DevtronL/), to keep yourself updated on this Open Source project.

Thanks for reading!

Connect with me: [Linkedin](https://www.linkedin.com/in/gargee-bhatnagar-6b7223114)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38sdi4nsp89fnui8h7dk.png)