我对如何使用 SSM 端点以便隔 ionic 网上的 Lambda 可以使用 ssm.GetParameter 感到非常困惑
根据this issue我需要 SSM 的 VPC 终端节点。我尝试这样做:
// Create a security group:
this.vpcsg = new ec2.SecurityGroup(this, 'vpc-sg', {
vpc: this.vpc,
allowAllOutbound: false,
securityGroupName: 'VPCSecurityGroup'
})
// endpoint creation
this.vpcEndpointSSM = new ec2.InterfaceVpcEndpoint(this, `SSMVpcEndpoint`, {
service: ec2.InterfaceVpcEndpointAwsService.SSM,
vpc: this.vpc,
subnets: { subnetType: ec2.SubnetType.ISOLATED },
securityGroups: [this.ingressSecurityGroup]
})
// And then later I call...
this.lambdaGQLAPI = new lambda.Function(this, `LambdaAPI`, {
code: new lambda.AssetCode(lambdaNodePath),
vpc: this.vpc,
vpcSubnets: { subnetType: ec2.SubnetType.ISOLATED },
functionName: this.functions.api,
handler: 'lambda_graphql.handler',
memorySize: 256,
timeout: core.Duration.minutes(2),
runtime: lambda.Runtime.NODEJS_12_X,
securityGroups: [props.dbSecurityGroup, this.vpcsg],
})
我还确保 lambda 函数应该能够使用策略模拟器访问 SSM,并进行检查
但是我的函数在尝试访问 SSM 时超时。
最佳答案
安全组单独应用于每个资源。安全组与子网不同。资源不驻留在安全组“内部”。
同一安全组中的资源无法相互通信,除非安全组中有特定规则授予自身访问权限。
例如,安全组可以有一条允许入站端口 80 的规则,且源是同一安全组。这意味着具有该安全组的资源可以接收来自与同一安全组关联的其他资源的流量。
但是,通常最好定义两个安全组:
- Lambda 函数 (
Lambda-SG
) 上的一个安全组允许所有出站访问 - VPC 端点 (
Endpoint-SG
) 上的一个安全组允许来自Lambda-SG
的入站流量
即,Endpoint-SG
特指Lambda-SG
。
关于amazon-web-services - 隔离 VPC 子网中的 Lambda 函数无法访问 SSM 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66111461/