作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我做了什么:
"errorMessage": "An error occurred (AccessDeniedException) when calling the Invoke operation: User: arn:aws:sts::Account-A:assumed-role/role-for-vpc-peering-test/lambda1_in_vpc is not authorized to perform: lambda:InvokeFunction on resource: arn:aws:lambda:us-east-1:Account-B:function:lambda-vpc
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::Account B:role/role-for-Account-A"
}
}
access denied error
)中遗漏了一些东西。
response = client.invoke(
FunctionName='arn:aws:lambda:us-east-1:AccountB-id:function:lambda-vpc-peering',
InvocationType='RequestResponse', # Event
Payload=json.dumps(inputForInvoker)
)
responseJson = json.load(response['Payload'])
print('\n')
print(responseJson)
print('\n')
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::Account-id-A:role/role-for-vpc-peering-test"
},
"Action": "sts:AssumeRole"
}
]
}.
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::Account-b-id:role/role-for-7691-4701-2358"
}
}
最佳答案
所需的一般步骤承担账户 A 中的角色 以下 AWS 博客中列出了在账户 B 中执行某些操作(例如,在 B 中调用 lambda 函数):
import json
import boto3
client = boto3.client('lambda')
sts = boto3.client('sts')
def lambda_handler(event, context):
inputForInvoker = {'CustomerId': '123', 'Amount': 50 }
account_b = sts.assume_role(
RoleArn="<arn-of-assumbale-role-in-acccount-b>",
RoleSessionName="cross_acct_lambda"
)
ACCESS_KEY = account_b['Credentials']['AccessKeyId']
SECRET_KEY = account_b['Credentials']['SecretAccessKey']
SESSION_TOKEN = account_b['Credentials']['SessionToken']
# create service client using the assumed role credentials
# from account B
account_b_client = boto3.client(
'lambda',
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
aws_session_token=SESSION_TOKEN)
response = account_b_client.invoke(FunctionName='arn:aws:lambda:us-east-1:AccountB-id:function:lambda-vpc-peering', InvocationType='RequestResponse')
responseJson = json.load(response['Payload'])
print('\n') print(responseJson) print('\n')
- I created a VPC Peering connection between these accounts
关于amazon-web-services - 如何从账户 A 中的 Lambda(VPC 中的 Lambda)调用账户 B(VPC 中的此 Lambda)中的 AWS Lambda 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62256171/
我是一名优秀的程序员,十分优秀!