divyanayan awasthi
divyanayan awasthi

Reputation: 950

Attach a preexisting role in template.yml file while creating sam application through console

I am trying to create a sam application with a pre existing role through sam-cli.By default the sam clil creates new user roles with basic lambda exuection policies ,but as i want to run x-ray on my sam application i would want application to be created with existing user role.

Here is my template.yml

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  POCLambdaExecutionRole:
  Type: 'AWS::IAM::Role'
  SAMLocal:
    Type: AWS::Serverless::Function
    Properties:
      Handler: SAMLocal.lambda_handler
      Runtime: python2.7
    TracingConfig:
      Mode: Active
      Environment:
        Variables:
          dev_table: "MessageQueue"
      Events:
        SAMLocal:
          Type: Api
          Properties:
            Path: /
            Method: GET
  SAMLocal1:
    Type: AWS::Serverless::Function
    Properties:
      Handler: SAMLocal.lambda_handler
      Runtime: python2.7

How can i achieve the same .

found this article on stack overflow but does not really helps my casue Associate existing IAM role with EC2 instance in CloudFormation

Upvotes: 1

Views: 1795

Answers (2)

Yash Bindlish
Yash Bindlish

Reputation: 600

you can either set role or permission. If you do not define role for your funcition, SAM will create one role for every function. by default, it will scope for each funcition individually.

Declare Role outside your function in the fashion i have described in my solution role: arn:aws:iam::XXXXXX:role/role

Check THIS

Upvotes: 0

Yash Bindlish
Yash Bindlish

Reputation: 600

you need to put existing role in your yaml file in ARN format

role: arn:aws:iam::XXXXXX:role/role

Upvotes: 3

Related Questions