Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/cloudformation_compatibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Tracing All
KmsKeyArn All
DeadLetterQueue All
DeploymentPreference All
Layers All
AutoPublishAlias Ref of a CloudFormation Parameter Alias resources created by SAM uses a LocicalId <FunctionLogicalId+AliasName>. So SAM either needs a string for alias name, or a Ref to template Parameter that SAM can resolve into a string.
ReservedConcurrentExecutions All
============================ ================================== ========================
Expand Down Expand Up @@ -171,6 +172,20 @@ Cors All
================================== ======================== ========================


AWS::Serverless::Application
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

================================== ======================== ========================
Property Name Intrinsic(s) Supported Reasons
================================== ======================== ========================
Location None SAM expects exact values for the Location property
Parameters All
NotificationArns All
Tags All
TimeoutInMinutes All
================================== ======================== ========================


AWS::Serverless::SimpleTable
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
1 change: 1 addition & 0 deletions docs/globals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Currently, the following resources and properties are being supported:
Tags:
Tracing:
KmsKeyArn:
Layers:
AutoPublishAlias:
DeploymentPreference:

Expand Down
4 changes: 3 additions & 1 deletion docs/safe_lambda_deployments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ resource:
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: Resource
Value: !Ref MyLambdaFunction.Version
Value: !Sub "${MyLambdaFunction}:live"
- Name: FunctionName
Value: !Ref MyLambdaFunction
- Name: ExecutedVersion
Value: !GetAtt MyLambdaFunction.Version.Version
EvaluationPeriods: 2
MetricName: Errors
Namespace: AWS/Lambda
Expand Down
8 changes: 8 additions & 0 deletions examples/2016-10-31/nested_app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Nested App Example

This app uses the [twitter event source app](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:077246666028:applications~aws-serverless-twitter-event-source) as a nested app and logs the tweets received from the nested app.

All you need to do is supply the desired parameters for this app and deploy. SAM will create a nested stack for any nested app inside of your template with all of the parameters that are passed to it.

## Installation Instructions
Please refer to the Installation Steps section of the [twitter-event-source application](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:077246666028:applications~aws-serverless-twitter-event-source) for detailed information regarding how to obtain and use the tokens and secrets for this application.
7 changes: 7 additions & 0 deletions examples/2016-10-31/nested_app/src/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import logging

LOGGER = logging.getLogger()
LOGGER.setLevel(logging.INFO)

def process_tweets(tweets, context):
LOGGER.info("Received tweets: {}".format(tweets))
56 changes: 56 additions & 0 deletions examples/2016-10-31/nested_app/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: This example imports the aws-serverless-twitter-event-source serverless app as a nested app in this serverless application and connects it to a function that will log the tweets sent for the given Twitter search text.
Parameters:
EncryptedAccessToken:
Type: String
Description: Twitter API Access Token encrypted ciphertext blob as a base64-encoded string.
EncryptedAccessTokenSecret:
Type: String
Description: Twitter API Access Token Secret ciphertext blob as a base64-encoded string.
EncryptedConsumerKey:
Type: String
Description: Twitter API Consumer Key encrypted ciphertext blob as a base64-encoded string.
EncryptedConsumerSecret:
Type: String
Description: Twitter API Consumer Secret encrypted ciphertext blob as a base64-encoded string.
DecryptionKeyName:
Type: String
Description: KMS key name of the key used to encrypt the Twitter API parameters. Note, this must be just the key name (UUID), not the full key ARN. It's assumed the key is owned by the same account, in the same region as the app.
SearchText:
Type: String
Description: Non-URL-encoded search text poller should use when querying Twitter Search API.
Default: AWS

Resources:
TweetLoggerFunction:
Type: 'AWS::Serverless::Function'
Properties:
Handler: app.process_tweets
Runtime: python3.6
MemorySize: 128
Timeout: 10
CodeUri: src/
TwitterEventSourceApp:
Type: 'AWS::Serverless::Application'
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:us-east-1:077246666028:applications/aws-serverless-twitter-event-source
SemanticVersion: 1.1.0
Parameters: # Using default value for PollingFrequencyInMinutes (1)
TweetProcessorFunctionName: !Ref TweetLoggerFunction
BatchSize: 20
DecryptionKeyName: !Ref DecryptionKeyName
EncryptedAccessToken: !Ref EncryptedAccessToken
EncryptedAccessTokenSecret: !Ref EncryptedAccessTokenSecret
EncryptedConsumerKey: !Ref EncryptedConsumerKey
EncryptedConsumerSecret: !Ref EncryptedConsumerSecret
SearchText: !Sub '${SearchText} -filter:nativeretweets' # filter out retweet records from search results
TimeoutInMinutes: 20

Outputs:
TweetLoggerFunctionArn:
Value: !GetAtt TweetLoggerFunction.Arn
TwitterSearchPollerFunctionArn:
# Reference an output from the nested stack:
Value: !GetAtt TwitterEventSourceApp.Outputs.TwitterSearchPollerFunctionArn
41 changes: 41 additions & 0 deletions examples/2016-10-31/workmail-hello-world-python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# AWS WorkMail hello world

This is a hello world example of the WorkMail lambda feature. For more information see [AWS WorMail lambda documentation](https://docs.aws.amazon.com/workmail/latest/adminguide/lambda.html)

To use this application you can deploy it via Lambda console. Visit [AWS Lambda Console](https://console.aws.amazon.com/lambda/home?region=us-east-1#/create?firstrun=true&tab=serverlessApps)

### Local development

First, [set up the SAM CLI](https://github.com/awslabs/aws-sam-cli/blob/develop/docs/installation.rst).

Now, test the application locally using:

`sam local invoke WorkMailHelloWorldFunction -e event.json`

### Deploying

```bash
sam package \
--template-file template.yaml \
--output-template-file packaged.yaml \
--s3-bucket $YOUR_BUCKET_NAME
```

```bash
sam deploy \
--template-file packaged.yaml \
--stack-name workmail-hello-world \
--capabilities CAPABILITY_IAM
```

### Configure WorkMail
Find the ARN of your new lambda function using:

```bash
aws cloudformation describe-stacks \
--stack-name workmail-hello-world \
--query 'Stacks[].Outputs[0].OutputValue'
```

Now you can go to WorkMail console and configure an outbound rule to use your new lambda.

17 changes: 17 additions & 0 deletions examples/2016-10-31/workmail-hello-world-python/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"summaryVersion": "2018-10-10",
"envelope": {
"mailFrom" : {
"address" : "[email protected]"
},
"recipients" : [
{ "address" : "[email protected]" },
{ "address" : "[email protected]" }
]
},
"sender" : {
"address" : "[email protected]"
},
"subject" : "Hello From Amazon WorkMail!",
"truncated": false
}
25 changes: 25 additions & 0 deletions examples/2016-10-31/workmail-hello-world-python/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
WorkMail hello world lambda SAM

Resources:
WorkMailHelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: workmail-hello-world/
Handler: app.lambda_handler
Runtime: python3.6
Timeout: 10

PermissionToCallLambdaAbove:
Type: AWS::Lambda::Permission
DependsOn: WorkMailHelloWorldFunction
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref WorkMailHelloWorldFunction
Principal: !Sub 'workmail.${AWS::Region}.amazonaws.com'

Outputs:
HelloWorldArn:
Value: !GetAtt WorkMailHelloWorldFunction.Arn
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""

Hello world example for AWS WorkMail

Parameters
----------
event: dict, required
AWS WorkMail Message Summary Input Format
For more information, see https://docs.aws.amazon.com/workmail/latest/adminguide/lambda.html

{
"summaryVersion": "2018-10-10", # AWS WorkMail Message Summary Version
"envelope": {
"mailFrom" : {
"address" : "[email protected]" # String containing from email address
},
"recipients" : [ # List of all recipient email addresses
{ "address" : "[email protected]" },
{ "address" : "[email protected]" }
]
},
"sender" : {
"address" : "[email protected]" # String containing sender email address
},
"subject" : "Hello From Amazon WorkMail!", # String containing email subject (Truncated to first 256 chars)"
"truncated": false # boolean indicating if any field in message was truncated due to size limitations
}

context: object, required
Lambda Context runtime methods and attributes

Attributes
----------

context.aws_request_id: str
Lambda request ID
context.client_context: object
Additional context when invoked through AWS Mobile SDK
context.function_name: str
Lambda function name
context.function_version: str
Function version identifier
context.get_remaining_time_in_millis: function
Time in milliseconds before function times out
context.identity:
Cognito identity provider context when invoked through AWS Mobile SDK
context.invoked_function_arn: str
Function ARN
context.log_group_name: str
Cloudwatch Log group name
context.log_stream_name: str
Cloudwatch Log stream name
context.memory_limit_in_mb: int
Function memory

https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html

Returns
------
Nothing
"""
def lambda_handler(event, context):
try:
fromAddress = event['envelope']['mailFrom']['address']
subject = event['subject']
print(f"Received Email from {fromAddress} with Subject {subject}")

except Exception as e:
# Send some context about this error to Lambda Logs
print(e)
raise e

2 changes: 1 addition & 1 deletion samtranslator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.8.0'
__version__ = '1.9.0'
Loading