AWS SAM allows you to choose from a list of policy templates to scope the permissions of your Lambda functions to the resources that are used by your application.
AWS SAM applications in the AWS Serverless Application Repository that use policy templates don't require any special customer acknowledgments to deploy the application from the AWS Serverless Application Repository.
If you want to request a new policy template to be added, do the following:
-
Submit a pull request against the policy_templates.json source file in the
develop
branch of the AWS SAM GitHub project. You can find the source file in policy_templates.json on the GitHub website. -
Submit an issue in the AWS SAM GitHub project that includes the reasons for your pull request and a link to the request. Use this link to submit a new issue: AWS Serverless Application Model: Issues.
For every policy template you specify in your AWS SAM template file, you must always specify an object containing the policy template's placeholder values. If a policy template does not require any placeholder values, you must specify an empty object.
MyFunction:
Type: AWS::Serverless::Function
Properties:
Policies:
- PolicyTemplateName1: # Policy template with placeholder value
Key1: Value1
- PolicyTemplateName2: {} # Policy template with no placeholder value
The following example shows that the SQSPollerPolicy policy template expects a QueueName
as a resource. The AWS SAM template retrieves the name of the "MyQueue
" Amazon SQS queue, which you can create in the same application or requested as a parameter to the application.
1. MyFunction:
2. Type: 'AWS::Serverless::Function'
3. Properties:
4. CodeUri: ${codeuri}
5. Handler: hello.handler
6. Runtime: python2.7
7. Policies:
8. - SQSPollerPolicy:
9. QueueName:
10. !GetAtt MyQueue.QueueName
The following example contains the CloudWatchPutMetricPolicy policy template, which has no placeholder values.
Note
Even though there are no placeholder values, you must specify an empty object, otherwise an error will result.
1. MyFunction:
2. Type: 'AWS::Serverless::Function'
3. Properties:
4. CodeUri: ${codeuri}
5. Handler: hello.handler
6. Runtime: python2.7
7. Policies:
8. - CloudWatchPutMetricPolicy: {}
The following is a table of the available policy templates.
Policy Template | Description |
---|---|
SQSPollerPolicy | Gives permission to poll an Amazon Simple Queue Service (Amazon SQS) queue. |
LambdaInvokePolicy | Gives permission to invoke an AWS Lambda function, alias, or version. |
CloudWatchDescribeAlarmHistoryPolicy | Gives permission to describe CloudWatch alarm history. |
CloudWatchPutMetricPolicy | Gives permission to send metrics to CloudWatch. |
EC2DescribePolicy | Gives permission to describe Amazon Elastic Compute Cloud (Amazon EC2) instances. |
DynamoDBCrudPolicy | Gives create, read, update, and delete permissions to an Amazon DynamoDB table. |
DynamoDBReadPolicy | Gives read-only permission to a DynamoDB table. |
DynamoDBWritePolicy | Gives write-only permission to a DynamoDB table. |
DynamoDBReconfigurePolicy | Gives permission to reconfigure a DynamoDB table. |
SESSendBouncePolicy | Gives SendBounce permission to an Amazon Simple Email Service (Amazon SES) identity. |
ElasticsearchHttpPostPolicy | Gives POST permission to Amazon Elasticsearch Service. |
S3ReadPolicy | Gives read-only permission to read objects in an Amazon Simple Storage Service (Amazon S3) bucket. |
S3WritePolicy | Gives write permission to write objects into an Amazon S3 bucket. |
S3CrudPolicy | Gives create, read, update, and delete permission to act on the objects in an Amazon S3 bucket. |
AMIDescribePolicy | Gives permission to describe Amazon Machine Images (AMIs). |
CloudFormationDescribeStacksPolicy | Gives permission to describe AWS CloudFormation stacks. |
RekognitionDetectOnlyPolicy | Gives permission to detect faces, labels, and text. |
RekognitionNoDataAccessPolicy | Gives permission to compare and detect faces and labels. |
RekognitionReadPolicy | Gives permission to list and search faces. |
RekognitionWriteOnlyAccessPolicy | Gives permission to create collection and index faces. |
SQSSendMessagePolicy | Gives permission to send message to an Amazon SQS queue. |
SNSPublishMessagePolicy | Gives permission to publish a message to an Amazon Simple Notification Service (Amazon SNS) topic. |
VPCAccessPolicy | Gives access to create, delete, describe, and detach elastic network interfaces. |
DynamoDBStreamReadPolicy | Gives permission to describe and read DynamoDB streams and records. |
KinesisStreamReadPolicy | Gives permission to list and read an Amazon Kinesis stream. |
SESCrudPolicy | Gives permission to send email and verify identity. |
SNSCrudPolicy | Gives permission to create, publish, and subscribe to Amazon SNS topics. |
KinesisCrudPolicy | Gives permission to create, publish, and delete an Amazon Kinesis stream. |
KMSDecryptPolicy | Gives permission to decrypt with an AWS Key Management Service (AWS KMS) key. |
KMSEncryptPolicy | Gives permission to encrypt with an AWS Key Management Service (AWS KMS) key. |
PollyFullAccessPolicy | Gives full access permission to Amazon Polly lexicon resources. |
S3FullAccessPolicy | Gives full access permission to act on the objects in an Amazon S3 bucket. |
CodePipelineLambdaExecutionPolicy | Gives permission for a Lambda function invoked by CodePipeline to report the status of the job. |
ServerlessRepoReadWriteAccessPolicy | Gives permission to create and list applications in the AWS Serverless Application Repository service. |
EC2CopyImagePolicy | Gives permission to copy Amazon EC2 images. |
AWSSecretsManagerRotationPolicy | Gives permission to rotate a secret in AWS Secrets Manager. |
AWSSecretsManagerGetSecretValuePolicy | Gives permission to get the secret value for the specified AWS Secrets Manager secret. |
CodePipelineReadOnlyPolicy | Gives read permission to get details about a CodePipeline pipeline. |
CloudWatchDashboardPolicy | Gives permissions to put metrics to operate on CloudWatch dashboards. |
RekognitionFacesManagementPolicy | Gives permission to add, delete, and search faces in an Amazon Rekognition collection. |
RekognitionFacesPolicy | Gives permission to compare and detect faces and labels. |
RekognitionLabelsPolicy | Gives permission to detect object and moderation labels. |
DynamoDBBackupFullAccessPolicy | Gives read and write permission to DynamoDB on-demand backups for a table. |
DynamoDBRestoreFromBackupPolicy | Gives permission to restore a DynamoDB table from backup. |
ComprehendBasicAccessPolicy | Gives permission for detecting entities, key phrases, languages, and sentiments. |
MobileAnalyticsWriteOnlyAccessPolicy | Gives write-only permission to put event data for all application resources. |
PinpointEndpointAccessPolicy | Gives permission to get and update endpoints for an Amazon Pinpoint application. |
FirehoseWritePolicy | Gives permission to write to a Kinesis Data Firehose delivery stream. |
FirehoseCrudPolicy | Gives permission to create, write, update, and delete a Kinesis Data Firehose delivery stream. |
EKSDescribePolicy | Gives permission to describe or list Amazon EKS clusters. |
CostExplorerReadOnlyPolicy | Gives read-only permission to the read-only Cost Explorer APIs for billing history. |
OrganizationsListAccountsPolicy | Gives read-only permission to list child account names and IDs. |
SESBulkTemplatedCrudPolicy | Gives permission to send email, templated email, templated bulk emails and verify identity. |
SESEmailTemplateCrudPolicy | Gives permission to create, get, list, update and delete Amazon SES email templates. |
FilterLogEventsPolicy | Gives permission to filter CloudWatch Logs events from a specified log group. |
SSMParameterReadPolicy | Gives permission to access a parameters from an Amazon EC2 Systems Manager (SSM) parameter store to load secrets in this account. |
StepFunctionsExecutionPolicy | Gives permission to start a Step Functions state machine execution. |
CodeCommitCrudPolicy | Gives permissions to create/read/update/delete objects within a specific CodeCommit repository. |
CodeCommitReadPolicy | Gives permissions to read objects within a specific CodeCommit repository. |
AthenaQueryPolicy | Gives permissions to execute Athena queries. |
TextractPolicy | Gives full access to Amazon Textract. |
TextractDetectAnalyzePolicy | Gives access to detect and analyze documents with Amazon Textract. |
TextractGetResultPolicy | Gives access to get detected and analyzed documents from Amazon Textract. |
EventBridgePutEventsPolicy | Gives permissions to send events to EventBridge. |
ElasticMapReduceModifyInstanceFleetPolicy | Gives permission to list details and modify capacities for instance fleets within a cluster. |
ElasticMapReduceSetTerminationProtectionPolicy | Gives permission to set termination protection for a cluster. |
ElasticMapReduceModifyInstanceGroupsPolicy | Gives permission to list details and modify settings for instance groups within a cluster. |
ElasticMapReduceCancelStepsPolicy | Gives permission to cancel a pending step or steps in a running cluster. |
ElasticMapReduceTerminateJobFlowsPolicy | Gives permission to shut down a cluster. |
ElasticMapReduceAddJobFlowStepsPolicy | Gives permission to add new steps to a running cluster. |
SageMakerCreateEndpointPolicy | Gives permission to create an endpoint in SageMaker. |
SageMakerCreateEndpointConfigPolicy | Gives permission to create an endpoint configuration in SageMaker. |
EcsRunTaskPolicy | Gives permission to start a new task for a task definition. |
EFSWriteAccessPolicy | Gives permission to mount an Amazon EFS file system with write access. |
Route53ChangeResourceRecordSetsPolicy | Gives permission to change resource record sets in Route 53. |
When executing sam build
, you see the following error:
"Must specify valid parameter values for policy template '<policy-template-name>'"
This means that you did not pass an empty object when declaring a policy template that does not have any placeholder values.
To fix this, declare the policy like the following example for CloudWatchPutMetricPolicy.
1. MyFunction:
2. Policies:
3. - CloudWatchPutMetricPolicy: {}