CCCC
CCCC

Reputation: 6469

aws cloudformation - Value at 'content.s3Bucket' failed to satisfy constraint: Member must satisfy regular expression pattern

I was going to access the s3 bucket for the zip file.
When I use below code, it can access the bucket because it uses root directory of the bucket.

"S3Bucket": { "Ref": "HandlerCodeS3Bucket" },

when I want to access the layers folder of same bucket, I use HandlerCodeS3BucketLayer parameters.
But it shows below error.

1 validation error detected: Value 'admin-sourcecode/layers' at 'content.s3Bucket' failed to satisfy constraint: Member must satisfy regular expression pattern: ^[0-9A-Za-z\.\-_]*(?<!\.)$ (Service: AWSLambdaInternal; Status Code: 400; Error Code: ValidationException; Request ID: xxx)
{
    "AWSTemplateFormatVersion": "2010-09-09",
    
    "Parameters": {
      "HandlerCodeS3Bucket": {
        "Type": "String",
        "Default": "admin-sourcecode"
      },
      "HandlerCodeS3BucketLayer": {
        "Type": "String",
        "Default": "admin-sourcecode/layers"
      }
    },
    "Resources": {
      "MyLayer": {
        "Type": "AWS::Lambda::LayerVersion",
        "Properties": {
            "CompatibleRuntimes": [
                "nodejs12.x"
            ],
            "Content": {
                "S3Bucket": {
                  "Ref": "HandlerCodeS3BucketLayer"
                },
                "S3Key": "imageUploadLayer.zip"
            },
            "Description": "My layer",
            "LayerName": "imageLayer",
            "LicenseInfo": "MIT"
        }
    }
   }
  }

Upvotes: 1

Views: 3685

Answers (1)

Marcin
Marcin

Reputation: 238259

Bucket name can't contain slashes:

admin-sourcecode/layers

Maybe in your code it should be:

{
    "AWSTemplateFormatVersion": "2010-09-09",
    
    "Parameters": {
      "HandlerCodeS3Bucket": {
        "Type": "String",
        "Default": "admin-sourcecode"
      },
      "HandlerCodeS3BucketLayer": {
        "Type": "String",
        "Default": "admin-sourcecode"
      }
    },
    "Resources": {
      "MyLayer": {
        "Type": "AWS::Lambda::LayerVersion",
        "Properties": {
            "CompatibleRuntimes": [
                "nodejs12.x"
            ],
            "Content": {
                "S3Bucket": {
                  "Ref": "HandlerCodeS3BucketLayer"
                },
                "S3Key": "layers/imageUploadLayer.zip"
            },
            "Description": "My layer",
            "LayerName": "imageLayer",
            "LicenseInfo": "MIT"
        }
    }
   }
  }

Upvotes: 2

Related Questions