I'm not fully grasping the flow with publishing/deploying with sam. My biggest hiccup is that my sam template declares a AWS::Serverless::Function
and the CodeUri parameter forces me to put in a s3 bucket url.
I've seen examples where the CodeUri is just the path to the code resources on your computer. When I try this sam complains
'CodeUri' is not a valid S3 Uri of the form "s3://bucket/key" with optional versionId query parameter.
To get around this I have to
This is painstakingly obnoxious.
What am I missing?
{
"Description" : "Serverless backend",
"Transform" : "AWS::Serverless-2016-10-31",
"Globals" : {
},
"Resources" : {
"db" : {
"Type": "AWS::RDS::DBInstance",
"Properties" : {
"AllocatedStorage": "20",
"DBInstanceClass": "db.t2.micro",
"DBName": "nameforthedb",
"DeleteAutomatedBackups": true,
"Engine": "postgres",
"MasterUsername": "masterUserName",
"MasterUserPassword": "******",
"PubliclyAccessible": true
}
},
"signIn" : {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "index.signIn",
"Runtime": "nodejs8.10",
"CodeUri": "src", <--- complains when this is set to this. Code lives in the src folder. this is fine when I run sam package, but has to be changed to the s3 bucket when running sam deploy
"FunctionName": "signIn",
"Events": {
"SignIn" : {
"Type": "Api",
"Properties" : {
"Path" : "/signIn",
"Method" : "post"
}
}
}
}
},
"Auth" : {
"Type" : "AWS::Cognito::UserPool",
"Properties": {
"Schema" : [
{
"AttributeDataType": "String",
"Name": "email",
"Mutable": true,
"Required": true
},
{
"AttributeDataType": "String",
"Name": "family_name",
"Mutable": true,
"Required": true
},
{
"AttributeDataType": "String",
"Name": "given_name",
"Mutable": true,
"Required": true
},
{
"AttributeDataType": "String",
"Name": "houseId",
"Mutable": true
},
{
"AttributeDataType": "Boolean",
"Name": "owner",
"Mutable": true
}
],
"UsernameAttributes": ["email"]
}
}
}
}
TemporaryFix's comment is the right answer to this. AWS SAM is correctly uploading artifacts to s3 and then produces the updated template file. You need to specify the --template-output-path packaged.yaml
when running sam package
, this command will then generate the file with a reference to s3 bucket for your function. You then have to specify --template-file packaged.yaml
when running the deploy command
something like:
sam build
sam package --s3-bucket your-bucket --output-template-file packaged.yaml
sam deploy --template-file packaged.yaml \
--region eu-west-1 \
--capabilities CAPABILITY_IAM \
--stack-name your-stack