要解决AWS Lambda在VPC中无法发送到Event Bridge的问题,您可以按照以下步骤进行操作:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowEventBridgeAccess",
"Effect": "Allow",
"Action": [
"events:PutEvents"
],
"Resource": "*"
}
]
}
这将授予Lambda函数向Event Bridge发送事件的权限。
以下是一个示例的Lambda函数配置,使其位于具有Internet访问权限的子网中:
Resources:
MyLambdaFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: my-lambda-function/
Handler: index.handler
Runtime: nodejs14.x
VpcConfig:
SubnetIds:
- subnet-12345678
SecurityGroupIds:
- security-group-12345678
请注意,subnet-12345678
和security-group-12345678
应该是具有Internet访问权限的子网和安全组的实际ID。
import boto3
def lambda_handler(event, context):
event_bridge = boto3.client('events', endpoint_url='https://events..amazonaws.com')
# 发送事件到Event Bridge的代码...
在endpoint_url
参数中,将
替换为您配置的Event Bridge终端节点所在的AWS区域。
通过执行以上步骤,您应该能够解决Lambda函数在VPC中无法发送到Event Bridge的问题。