I am trying to invoke lambda from my pipeline using the below command where I need to pass the ami as input variable to lambda.
aws lambda invoke --function-name SuccessLambda --cli-binary-format raw-in-base64-out --payload '{"ami":"ami-1234"}' response.json
my lambda function should read this, please help with the syntax -
import json
import boto3
import os
ami=event.ami
sns = boto3.client('sns')
def lambda_handler(event, context):
ami = $(event.ami)
message = "The new ami %s is now available" % (ami)
response = sns.publish(
TopicArn = "arn:SuccessArtifactsNotificationTopic",
Message = message,
Subject=(Subject)
)
return {
'statusCode': 200,
'body': json.dumps('Success!')
}
Please find the below solution -
aws lambda invoke --function-name SuccessArtifactsNotificationLambda --cli-binary-format raw-in-base64-out --payload '{"ami":"ami-1234"}' response.json
This is how you can call the variable in lambda-
import json
import boto3
import os
sns = boto3.client('sns')
def lambda_handler(event, context):
ami = event['ami']
message = "The new ami %s is now available" % (ami)
response = sns.publish(
TopicArn = "arn:SuccessTopic",
Message = message,
Subject=(Subject)
)
return {
'statusCode': 200,
'body': json.dumps('Success!')
}