Beispiel #1
0
    def build_template(self, app_name, stage_name, bucket, zip_name,
                       stage_settings):
        sam = sm.SAM(Description=self.config.get('description'),
                     render_type='yaml')

        sam.add_parameter(sm.Parameter(name='Bucket', Type='String'))

        sam.add_parameter(sm.Parameter(name='CodeZipKey', Type='String'))

        app_stage = self.get_zip_name(app_name, stage_name, no_ext=True)

        sam.add_resource(
            sm.Function(name=app_name,
                        CodeUri=sm.S3URI(Bucket=sm.Ref(Ref='Bucket'),
                                         Key=sm.Ref(Ref='CodeZipKey')),
                        Handler='{app_name}.app.app'.format(app_name=app_name),
                        Runtime='python3.6',
                        Environment=sm.Environment(Variables=self.get_env_vars(
                            app_name, stage_name, stage_settings)),
                        Events=[
                            sm.APIEvent(name=app_name,
                                        Path='{proxy+}',
                                        Method='get')
                        ]))
        try:
            sam.publish(app_name, Bucket=bucket, CodeZipKey=zip_name)
        except ChangeEmptyError:
            print('New Zip uploaded, CloudFormation template unchanged,')
Beispiel #2
0
import sammy as sm

sam = sm.SAM(
    Description=
    'Simple CRUD webservice. State is stored in a SimpleTable (DynamoDB) resource.'
)

sam.add_resource(
    sm.Function(name='GetFunction',
                CodeUri=sm.S3URI(Bucket='<bucket>', Key='sammytest.zip'),
                Handler='index.get',
                Runtime='python3.6',
                Policies='AmazonDynamoDBReadOnlyAccess',
                Environment=sm.Environment(
                    Variables={'TABLE_NAME': sm.Ref(Ref='Table')}),
                Events=[
                    sm.APIEvent(name='GetResource',
                                Path='/resource/{resourceId}',
                                Method='get')
                ]))

sam.add_resource(
    sm.Function(name='PutFunction',
                Handler='index.put',
                Runtime='python3.6',
                CodeUri=sm.S3URI(Bucket='<bucket>', Key='sammytest.zip'),
                Policies='AmazonDynamoDBFullAccess',
                Environment=sm.Environment(
                    Variables={'TABLE_NAME': sm.Ref(Ref='Table')}),
                Events=[
                    sm.APIEvent(name='PutResource',
Beispiel #3
0
                           "Service": ["lambda.amazonaws.com"]
                       },
                       "Action": ["sts:AssumeRole"]
                   }]
               },
               ManagedPolicyArns=[
                   'arn:aws:iam::aws:policy/AmazonSQSFullAccess',
                   'arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess',
                   'arn:aws:iam::aws:policy/CloudWatchLogsFullAccess'
               ],
               RoleName='loadlamb')

f = sm.Function(
    name='loadlambpush',
    FunctionName='loadlamb-run',
    CodeUri=sm.S3URI(Bucket=sm.Ref(Ref='CodeBucket'),
                     Key=sm.Ref(Ref='CodeZipKey')),
    Handler='loadlamb.chalicelib.lambdas.run_handler',
    Runtime='python3.6',
    Timeout=900,
    MemorySize=3008,
    Role=sm.Sub(Sub='arn:aws:iam::${AWS::AccountId}:role/loadlamb'),
    Environment=env)

s = sm.SAM(render_type='yaml')
s.add_parameter(sm.Parameter(name='CodeBucket', Type='String'))
s.add_parameter(sm.Parameter(name='CodeZipKey', Type='String'))

s.add_resource(f)

r = sm.CFT(render_type='yaml')
Beispiel #4
0
                              'WriteCapacityUnits': 5
                          }
                      }],
                      AttributeDefinitions=[{
                          'AttributeName': '_id',
                          'AttributeType': 'S'
                      }, {
                          'AttributeName': 'run_slug',
                          'AttributeType': 'S'
                      }],
                      ProvisionedThroughput={
                          'ReadCapacityUnits': 5,
                          'WriteCapacityUnits': 5
                      })

env = sm.Environment(Variables={'DYNAMODB_TABLE': sm.Ref(Ref='loadlambddb')})

role = sm.Role(name='loadlambpolicy',
               AssumeRolePolicyDocument={
                   "Version":
                   "2012-10-17",
                   "Statement": [{
                       "Effect": "Allow",
                       "Principal": {
                           "Service": ["lambda.amazonaws.com"]
                       },
                       "Action": ["sts:AssumeRole"]
                   }]
               },
               ManagedPolicyArns=[
                   'arn:aws:iam::aws:policy/AmazonSQSFullAccess',
Beispiel #5
0
import sammy as sm

sam = sm.SAM(Description='A hello world application.', render_type='yaml')

sam.add_parameter(sm.Parameter(name='Bucket', Type='String'))

sam.add_parameter(sm.Parameter(name='CodeZipKey', Type='String'))

sam.add_resource(
    sm.Function(name='HelloWorldFunction',
                Handler='sample.handler',
                Runtime='python3.6',
                CodeUri=sm.S3URI(Bucket=sm.Ref(Ref='Bucket'),
                                 Key=sm.Ref(Ref='CodeZipKey'))))