当我尝试使用
sls deploy --stage dev
部署应用程序时,它会运行几分钟,我可以看到在我的 AWS 账户中创建的大部分资源,但最终失败并显示:
✖ An error occurred: CheckDashindexDashsizeLambdaFunction - Resource handler returned message: "EFS file system arn:aws:elasticfilesystem:us-east-1:<account_id>:file-system/fs-<id1> referenced by access point arn:aws:elasticfilesystem:us-east-1:<account_id>:access-point/fsap-<id2> has mount targets created in all availability zones the function will execute in, but not all are in the available life cycle state yet. Please wait for them to become available and try the request again. (Service: Lambda, Status Code: 400, Request ID: ac1b6016-fd2d-4306-a7f1-745295b7cdb6)"
我第一次运行这个命令时,效果很好。但后来我运行了
sls remove --stage dev
来清除所有内容,以便我可以进行干净的重新部署。现在,每次我尝试部署时,都会收到此错误。
它建议重试,但我在过去 6 小时内重新运行部署 10 次,每次都失败。这只是 AWS 端的问题还是我的配置错误?
我的 serverless.yml 如下所示:
org: ${env:ORG}
service: lucene-serverless-${env:APP_NAME}
variablesResolutionMode: 20210219
custom:
name: ${sls:stage}-${self:service}
region: ${opt:region, "us-east-1"}
vpcId: ${env:LUCENE_SERVERLESS_VPC_ID}
subnetId1: ${env:SUBNET_ID1}
subnetId2: ${env:SUBNET_ID2}
javaVersion: provided.al2
provider:
name: aws
profile: ${env:PROFILE}
region: ${self:custom.region}
versionFunctions: false
apiGateway:
shouldStartNameWithService: true
tracing:
lambda: false
timeout: 15
environment:
stage: prod
DISABLE_SIGNAL_HANDLERS: true
iam:
role:
statements: ${file(roleStatements.yml)}
vpc:
securityGroupIds:
- Ref: EfsSecurityGroup
subnetIds:
- ${self:custom.subnetId1}
- ${self:custom.subnetId2}
package:
individually: true
functions:
index:
name: ${self:custom.name}-index
runtime: ${self:custom.javaVersion}
handler: native.handler
reservedConcurrency: 1
memorySize: 256
timeout: 180
dependsOn:
- EfsMountTarget1
- EfsMountTarget2
- EfsAccessPoint
fileSystemConfig:
localMountPath: /mnt/data
arn:
Fn::GetAtt: [EfsAccessPoint, Arn]
package:
artifact: target/function.zip
environment:
QUARKUS_LAMBDA_HANDLER: index
QUARKUS_PROFILE: prod
events:
- sqs:
arn:
Fn::GetAtt: [WriteQueue, Arn]
batchSize: 5000
maximumBatchingWindow: 5
enqueue-index:
name: ${self:custom.name}-enqueue-index
runtime: ${self:custom.javaVersion}
handler: native.handler
memorySize: 256
package:
artifact: target/function.zip
vpc:
securityGroupIds: []
subnetIds: []
events:
- http: POST /index
environment:
QUARKUS_LAMBDA_HANDLER: enqueue-index
QUARKUS_PROFILE: prod
QUEUE_URL:
Ref: WriteQueue
resources:
Resources:
WriteQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:custom.name}-write-queue
VisibilityTimeout: 900
RedrivePolicy:
deadLetterTargetArn:
Fn::GetAtt: [WriteDLQ, Arn]
maxReceiveCount: 5
WriteDLQ:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:custom.name}-write-dlq
MessageRetentionPeriod: 1209600 # 14 days in seconds
FileSystem:
Type: AWS::EFS::FileSystem
Properties:
BackupPolicy:
Status: DISABLED
FileSystemTags:
- Key: Name
Value: ${self:custom.name}-fs
PerformanceMode: generalPurpose
ThroughputMode: elastic # faster scale up/down
Encrypted: true
FileSystemPolicy:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- "elasticfilesystem:ClientMount"
Principal:
AWS: "*"
EfsSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
VpcId: ${self:custom.vpcId}
GroupDescription: "mnt target sg"
SecurityGroupIngress:
- IpProtocol: -1
CidrIp: "0.0.0.0/0"
- IpProtocol: -1
CidrIpv6: "::/0"
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: "0.0.0.0/0"
- IpProtocol: -1
CidrIpv6: "::/0"
EfsMountTarget1:
Type: AWS::EFS::MountTarget
Properties:
FileSystemId: !Ref FileSystem
SubnetId: ${self:custom.subnetId1}
SecurityGroups:
- Ref: EfsSecurityGroup
EfsMountTarget2:
Type: AWS::EFS::MountTarget
Properties:
FileSystemId: !Ref FileSystem
SubnetId: ${self:custom.subnetId2}
SecurityGroups:
- Ref: EfsSecurityGroup
EfsAccessPoint:
Type: "AWS::EFS::AccessPoint"
Properties:
FileSystemId: !Ref FileSystem
PosixUser:
Uid: "1000"
Gid: "1000"
RootDirectory:
CreationInfo:
OwnerGid: "1000"
OwnerUid: "1000"
Permissions: "0777"
Path: "/mnt/data"
是的,我已经确保定义了所有适当的环境变量。
为我解决这个问题的是本论坛中提到的建议,告诉无服务器访问点取决于使用
DependsOn
关键字的两个挂载目标。
例如
EfsAccessPoint:
Type: "AWS::EFS::AccessPoint"
Properties:
FileSystemId: !Ref FileSystem
PosixUser:
Uid: "1000"
Gid: "1000"
RootDirectory:
CreationInfo:
OwnerGid: "1000"
OwnerUid: "1000"
Permissions: "0777"
Path: "/mnt/data"
DependsOn:
- EfsMountTarget1
- EfsMountTarget2