How to run boto3 in Lambda Function

+1 vote

Hi,

I have two boto3(python) script for creating Users in AWS AppStream 2.0 and Assigning user to existing AppStream Stack. Its working fine from command line like my local system. But now i trying to implement this both script as single function(Creating user and assigning user to existing stack) in Lambda function. Whenever i run my lambda function code, it execute first part only like - it can create user whereas cant associate to existing running stack. I knew, i formatted my code not well in lambda function, due to poor knowledge in python. I have shared my lambda function here. Kindly correct it and reply me asap.  

Lambda function code - python3

#!/usr/bin/env python3

import botocore
import boto3

def lambda_handler(event, context):
    client = boto3.client('appstream',aws_access_key_id='xxxxxx',aws_secret_access_key='yyyyyy')
    session = boto3.Session(region_name='us-west-2')
    response = client.create_user(
        UserName='ram@example.com',
        FirstName='Ram',
        LastName='Nathan',
        AuthenticationType='USERPOOL'
    )
    response = client.batch_associate_user_stack(
        UserStackAssociations=[
            {
            'StackName': 'ss',
            'UserName': 'ram@example.com',
            'AuthenticationType': 'USERPOOL',
            'SendEmailNotification': True
            },
        ]
    )

Below are logs

Execution result: succeeded

The area below shows the result returned by your function execution. Learn more about returning results from your function.

null

Kindly correct my code to create user in user pool and associate created user to running AppStream stacks. aws

Sep 30, 2020 in AWS by Lakshminarayanan
• 1,370 points
1,874 views
Hi@Lakshminarayanan,

There is nothing wrong with your code. The official document also has the same methods and functions. Ok, do one thing give different variables names. And print them in your code.
Hi bro,

Its working fine after modifying

response for both Creating user and Associating user

 responseuser = client.create_user(....)

responsestack = client.batch_associate_user_stack(....)

Many thanks for your reply

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In AWS

0 votes
2 answers

How to kill a lambda function in AWS?

$ aws lambda put-function-concurrency --function-name my-function --reserved-concurrent-executions ...READ MORE

answered Mar 28, 2019 in AWS by Shashank
• 1,370 points
23,387 views
+1 vote
1 answer
0 votes
3 answers

How to check instance state and status via Lambda function in AWS?

import boto3 from pprint import pprint def lambda_handler(event, context):          # ...READ MORE

answered Sep 8, 2020 in AWS by Shrikant
• 180 points
10,381 views
0 votes
1 answer

How to setup an alarm when Lambda function fails in AWS?

Hi@akhtar, To create an Alarm for Lambda function, ...READ MORE

answered Apr 2, 2020 in AWS by MD
• 95,460 points
4,143 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP