Reputation: 345
I am working on SAM template for publishing my Application in AWS Serverless repository. But when I try to add policies for my lambda it shows me error: Invalid Serverless Application Specification document. Number of errors found: 1. Errors: Resource with id [SyncPostDataFromSfLambda] is invalid. Only policy templates are supported in 'Policies' property.
Below is the example for my SAM template:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Description": "Deployment",
"Resources": {
"SyncPostDataToSfLambda": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "index.handler",
"FunctionName": "myLambdaFunction",
"CodeUri": "s3 URL",
"Runtime": "nodejs6.10",
"MemorySize": 512,
"Policies": [
"AmazonDynamoDBFullAccess"
],
"Events": {
"PostResource": {
"Type": "Api",
"Properties": {
"RestApiId": {
"Ref": "API"
},
"Path": "/apipath",
"Method": "post"
}
}
}
}
}
}
}
Upvotes: 16
Views: 19835
Reputation: 1033
Here's the full list of policy templates from the official repo example.
Transform: AWS::Serverless-2016-10-31
Resources:
MyFunction:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: src/
Handler: index.handler
Runtime: nodejs4.3
Policies:
- SQSPollerPolicy:
QueueName: name
- LambdaInvokePolicy:
FunctionName: name
- CloudWatchPutMetricPolicy: {}
- EC2DescribePolicy: {}
- DynamoDBCrudPolicy:
TableName: name
- DynamoDBReadPolicy:
TableName: name
- SESSendBouncePolicy:
IdentityName: name
- ElasticsearchHttpPostPolicy:
DomainName: name
- S3ReadPolicy:
BucketName: name
- S3CrudPolicy:
BucketName: name
- AMIDescribePolicy: {}
- CloudFormationDescribeStacksPolicy: {}
- RekognitionDetectOnlyPolicy: {}
- RekognitionNoDataAccessPolicy:
CollectionId: id
- RekognitionReadPolicy:
CollectionId: id
- RekognitionWriteOnlyAccessPolicy:
CollectionId: id
- RekognitionLabelsPolicy: {}
- SQSSendMessagePolicy:
QueueName: name
- SNSPublishMessagePolicy:
TopicName: name
- VPCAccessPolicy: {}
- DynamoDBStreamReadPolicy:
TableName: name
StreamName: name
- KinesisStreamReadPolicy:
StreamName: name
- SESCrudPolicy:
IdentityName: name
- SNSCrudPolicy:
TopicName: name
- KinesisCrudPolicy:
StreamName: name
- KMSDecryptPolicy:
KeyId: keyId
- SESBulkTemplatedCrudPolicy:
IdentityName: name
- SESEmailTemplateCrudPolicy: {}
- FilterLogEventsPolicy:
LogGroupName: name
- StepFunctionsExecutionPolicy:
StateMachineName: name
Upvotes: 11
Reputation: 1131
As of today (2018-10-09), SAM template already supports inline policy document.
Here is an example:-
Resources:
SomeFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs8.10
Policies:
- Statement:
- Sid: SSMDescribeParametersPolicy
Effect: Allow
Action:
- ssm:DescribeParameters
Resource: '*'
- Sid: SSMGetParameterPolicy
Effect: Allow
Action:
- ssm:GetParameters
- ssm:GetParameter
Resource: '*'
References:
Upvotes: 24
Reputation: 31
It seems, that currently only SAM Policy Templates can be used.
AWS maintains the authoritative information/overview of SAM Policy Templates here: https://docs.aws.amazon.com/serverlessrepo/latest/devguide/using-aws-sam.html
This document also states that, if you need further AWS Resources and/or Policy Templates, you should contact the AWS Support.
A short overview and example of how to use them can be found here: https://github.com/awslabs/serverless-application-model/blob/master/examples/2016-10-31/policy_templates/all_policy_templates.yaml
Here's the overview of currently supported SAM Policy Templates at the time of posting this answer:
Almost any of those Policy Templates have to be configured. Please read the AWS documentation (links above) about how to configure these templates.
Upvotes: 3