此错误通常是由AWS凭证问题引起的。确保您的AWS访问密钥和密钥ID正确配置,并且正确向AWS授予必要的许可。
以下是示例SAM模板,其中包含使用Programmatic Account Access部署Lambda函数以及推送到ECR仓库的部署:
AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31
Resources: MyFunction: Type: AWS::Serverless::Function Properties: CodeUri: ./ Handler: index.handler Runtime: nodejs12.x Description: This is my sample Lambda function. Role: !Ref MyLambdaRole
MyLambdaRole: Type: AWS::IAM::Role Properties: RoleName: MyLambdaRole AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: lambda.amazonaws.com Action: sts:AssumeRole Policies: - PolicyName: root PolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Action: - logs:CreateLogGroup - logs:CreateLogStream - logs:PutLogEvents Resource: arn:aws:logs:::*
MyECRRepo: Type: AWS::ECR::Repository Properties: RepositoryName: my-ecr-repo
MyECRPolicy: Type: AWS::ECR::RepositoryPolicy Properties: RepositoryName: !Ref MyECRRepo PolicyText: | { "Version": "2008-10-17", "Statement": [ { "Sid": "new policy", "Effect": "Allow", "Principal": {"AWS": "!Sub arn:aws:iam::${AWS::AccountId}:root"}, "Action": ["ecr:BatchCheckLayerAvailability","ecr:GetDownloadUrlForLayer