golden hour
/opt/saltstack/salt/lib/python3.10/site-packages/salt/states
⬆️ Go Up
Upload
File/Folder
Size
Actions
__init__.py
25 B
Del
OK
__pycache__
-
Del
OK
acme.py
5.08 KB
Del
OK
alias.py
2.49 KB
Del
OK
alternatives.py
6.75 KB
Del
OK
ansiblegate.py
7.93 KB
Del
OK
apache.py
3.95 KB
Del
OK
apache_conf.py
2.72 KB
Del
OK
apache_module.py
2.73 KB
Del
OK
apache_site.py
2.66 KB
Del
OK
aptpkg.py
1.42 KB
Del
OK
archive.py
68.24 KB
Del
OK
artifactory.py
6.84 KB
Del
OK
at.py
7.48 KB
Del
OK
augeas.py
10.57 KB
Del
OK
aws_sqs.py
2.59 KB
Del
OK
azurearm_compute.py
11.78 KB
Del
OK
azurearm_dns.py
26.05 KB
Del
OK
azurearm_network.py
89.12 KB
Del
OK
azurearm_resource.py
28.23 KB
Del
OK
beacon.py
7.58 KB
Del
OK
bigip.py
96.63 KB
Del
OK
blockdev.py
5.13 KB
Del
OK
boto3_elasticache.py
48.01 KB
Del
OK
boto3_elasticsearch.py
32.58 KB
Del
OK
boto3_route53.py
37.54 KB
Del
OK
boto3_sns.py
12.69 KB
Del
OK
boto_apigateway.py
82.83 KB
Del
OK
boto_asg.py
31.93 KB
Del
OK
boto_cfn.py
11.53 KB
Del
OK
boto_cloudfront.py
6.01 KB
Del
OK
boto_cloudtrail.py
13.18 KB
Del
OK
boto_cloudwatch_alarm.py
6.4 KB
Del
OK
boto_cloudwatch_event.py
12.33 KB
Del
OK
boto_cognitoidentity.py
13.69 KB
Del
OK
boto_datapipeline.py
18.5 KB
Del
OK
boto_dynamodb.py
29.32 KB
Del
OK
boto_ec2.py
71.98 KB
Del
OK
boto_elasticache.py
16.75 KB
Del
OK
boto_elasticsearch_domain.py
12.27 KB
Del
OK
boto_elb.py
55.1 KB
Del
OK
boto_elbv2.py
12.19 KB
Del
OK
boto_iam.py
69.16 KB
Del
OK
boto_iam_role.py
27.12 KB
Del
OK
boto_iot.py
25.33 KB
Del
OK
boto_kinesis.py
16.69 KB
Del
OK
boto_kms.py
12.11 KB
Del
OK
boto_lambda.py
35.52 KB
Del
OK
boto_lc.py
11.04 KB
Del
OK
boto_rds.py
26 KB
Del
OK
boto_route53.py
19.49 KB
Del
OK
boto_s3.py
9.32 KB
Del
OK
boto_s3_bucket.py
24.67 KB
Del
OK
boto_secgroup.py
32.62 KB
Del
OK
boto_sns.py
8.92 KB
Del
OK
boto_sqs.py
7.97 KB
Del
OK
boto_vpc.py
62.23 KB
Del
OK
bower.py
8.26 KB
Del
OK
btrfs.py
10.34 KB
Del
OK
cabal.py
5.73 KB
Del
OK
ceph.py
1.9 KB
Del
OK
chef.py
3.76 KB
Del
OK
chocolatey.py
16.15 KB
Del
OK
chronos_job.py
4.6 KB
Del
OK
cimc.py
14.32 KB
Del
OK
cisconso.py
3.14 KB
Del
OK
cloud.py
14.4 KB
Del
OK
cmd.py
40.92 KB
Del
OK
composer.py
8.38 KB
Del
OK
consul.py
5.4 KB
Del
OK
cron.py
23.39 KB
Del
OK
cryptdev.py
6.17 KB
Del
OK
csf.py
9.98 KB
Del
OK
cyg.py
7.05 KB
Del
OK
ddns.py
4.2 KB
Del
OK
debconfmod.py
6.33 KB
Del
OK
dellchassis.py
24.49 KB
Del
OK
disk.py
6.49 KB
Del
OK
docker_container.py
85.27 KB
Del
OK
docker_image.py
16.7 KB
Del
OK
docker_network.py
36.78 KB
Del
OK
docker_volume.py
6.72 KB
Del
OK
drac.py
4.17 KB
Del
OK
dvs.py
26.29 KB
Del
OK
elasticsearch.py
20.38 KB
Del
OK
elasticsearch_index.py
3.25 KB
Del
OK
elasticsearch_index_template.py
3.67 KB
Del
OK
environ.py
5.81 KB
Del
OK
eselect.py
2.27 KB
Del
OK
esxcluster.py
22.4 KB
Del
OK
esxdatacenter.py
4.44 KB
Del
OK
esxi.py
63.07 KB
Del
OK
esxvm.py
20.11 KB
Del
OK
etcd_mod.py
11 KB
Del
OK
ethtool.py
9.88 KB
Del
OK
event.py
2.48 KB
Del
OK
file.py
316.7 KB
Del
OK
firewall.py
1.33 KB
Del
OK
firewalld.py
26.08 KB
Del
OK
gem.py
7.13 KB
Del
OK
git.py
123.85 KB
Del
OK
github.py
27.25 KB
Del
OK
glance_image.py
2.26 KB
Del
OK
glassfish.py
21.47 KB
Del
OK
glusterfs.py
12.21 KB
Del
OK
gnomedesktop.py
7.47 KB
Del
OK
gpg.py
5.28 KB
Del
OK
grafana.py
12.11 KB
Del
OK
grafana4_dashboard.py
17.31 KB
Del
OK
grafana4_datasource.py
6.15 KB
Del
OK
grafana4_org.py
7.73 KB
Del
OK
grafana4_user.py
5.52 KB
Del
OK
grafana_dashboard.py
17.74 KB
Del
OK
grafana_datasource.py
5.31 KB
Del
OK
grains.py
15.57 KB
Del
OK
group.py
9.84 KB
Del
OK
heat.py
9.69 KB
Del
OK
helm.py
10.39 KB
Del
OK
hg.py
6.33 KB
Del
OK
highstate_doc.py
1.41 KB
Del
OK
host.py
8.64 KB
Del
OK
http.py
7.46 KB
Del
OK
icinga2.py
9.07 KB
Del
OK
idem.py
3.91 KB
Del
OK
ifttt.py
2.12 KB
Del
OK
incron.py
5.71 KB
Del
OK
influxdb08_database.py
2.85 KB
Del
OK
influxdb08_user.py
3.39 KB
Del
OK
influxdb_continuous_query.py
2.83 KB
Del
OK
influxdb_database.py
2.11 KB
Del
OK
influxdb_retention_policy.py
4.82 KB
Del
OK
influxdb_user.py
4.84 KB
Del
OK
infoblox_a.py
4.24 KB
Del
OK
infoblox_cname.py
4.19 KB
Del
OK
infoblox_host_record.py
6.59 KB
Del
OK
infoblox_range.py
6.85 KB
Del
OK
ini_manage.py
12.67 KB
Del
OK
ipmi.py
8.42 KB
Del
OK
ipset.py
9.66 KB
Del
OK
iptables.py
27.65 KB
Del
OK
jboss7.py
23.95 KB
Del
OK
jenkins.py
3.36 KB
Del
OK
junos.py
17.78 KB
Del
OK
kapacitor.py
6.46 KB
Del
OK
kernelpkg.py
6.42 KB
Del
OK
keyboard.py
2.01 KB
Del
OK
keystone.py
27.12 KB
Del
OK
keystone_domain.py
2.81 KB
Del
OK
keystone_endpoint.py
4.69 KB
Del
OK
keystone_group.py
3.25 KB
Del
OK
keystone_project.py
3.36 KB
Del
OK
keystone_role.py
2.33 KB
Del
OK
keystone_role_grant.py
4.08 KB
Del
OK
keystone_service.py
2.89 KB
Del
OK
keystone_user.py
3.47 KB
Del
OK
keystore.py
5.67 KB
Del
OK
kmod.py
8.59 KB
Del
OK
kubernetes.py
24.87 KB
Del
OK
layman.py
2.44 KB
Del
OK
ldap.py
19.78 KB
Del
OK
libcloud_dns.py
5.7 KB
Del
OK
libcloud_loadbalancer.py
5.66 KB
Del
OK
libcloud_storage.py
5.13 KB
Del
OK
linux_acl.py
24.42 KB
Del
OK
locale.py
2.52 KB
Del
OK
logadm.py
4.67 KB
Del
OK
logrotate.py
3.86 KB
Del
OK
loop.py
7.74 KB
Del
OK
lvm.py
13.33 KB
Del
OK
lvs_server.py
6.28 KB
Del
OK
lvs_service.py
4.38 KB
Del
OK
lxc.py
22.17 KB
Del
OK
lxd.py
7.88 KB
Del
OK
lxd_container.py
22.25 KB
Del
OK
lxd_image.py
10.59 KB
Del
OK
lxd_profile.py
7.11 KB
Del
OK
mac_assistive.py
1.55 KB
Del
OK
mac_keychain.py
5.59 KB
Del
OK
mac_xattr.py
3.15 KB
Del
OK
macdefaults.py
2.65 KB
Del
OK
macpackage.py
6.76 KB
Del
OK
makeconf.py
6.87 KB
Del
OK
marathon_app.py
4.45 KB
Del
OK
mdadm_raid.py
6.41 KB
Del
OK
memcached.py
3.95 KB
Del
OK
modjk.py
2.84 KB
Del
OK
modjk_worker.py
6.49 KB
Del
OK
module.py
18.64 KB
Del
OK
mongodb_database.py
1.65 KB
Del
OK
mongodb_user.py
6.26 KB
Del
OK
monit.py
2.68 KB
Del
OK
mount.py
50.32 KB
Del
OK
mssql_database.py
3 KB
Del
OK
mssql_login.py
3.64 KB
Del
OK
mssql_role.py
2.37 KB
Del
OK
mssql_user.py
3.51 KB
Del
OK
msteams.py
2.53 KB
Del
OK
mysql_database.py
6.05 KB
Del
OK
mysql_grants.py
8.49 KB
Del
OK
mysql_query.py
13.07 KB
Del
OK
mysql_user.py
9.51 KB
Del
OK
net_napalm_yang.py
9.15 KB
Del
OK
netacl.py
31.92 KB
Del
OK
netconfig.py
33.42 KB
Del
OK
netntp.py
12.51 KB
Del
OK
netsnmp.py
11.33 KB
Del
OK
netusers.py
16.1 KB
Del
OK
network.py
23.97 KB
Del
OK
neutron_network.py
3.96 KB
Del
OK
neutron_secgroup.py
4 KB
Del
OK
neutron_secgroup_rule.py
4.75 KB
Del
OK
neutron_subnet.py
4.29 KB
Del
OK
nexus.py
4.97 KB
Del
OK
nfs_export.py
4.92 KB
Del
OK
nftables.py
19.5 KB
Del
OK
npm.py
11.21 KB
Del
OK
ntp.py
2.12 KB
Del
OK
nxos.py
10.37 KB
Del
OK
nxos_upgrade.py
3.5 KB
Del
OK
openstack_config.py
3.26 KB
Del
OK
openvswitch_bridge.py
4.36 KB
Del
OK
openvswitch_db.py
2.24 KB
Del
OK
openvswitch_port.py
17.24 KB
Del
OK
opsgenie.py
4.07 KB
Del
OK
pagerduty.py
1.89 KB
Del
OK
pagerduty_escalation_policy.py
5.42 KB
Del
OK
pagerduty_schedule.py
6.09 KB
Del
OK
pagerduty_service.py
3.93 KB
Del
OK
pagerduty_user.py
1.18 KB
Del
OK
panos.py
48.13 KB
Del
OK
pbm.py
20.46 KB
Del
OK
pcs.py
36.46 KB
Del
OK
pdbedit.py
3.43 KB
Del
OK
pecl.py
3.65 KB
Del
OK
pip_state.py
38.55 KB
Del
OK
pkg.py
138.08 KB
Del
OK
pkgbuild.py
11.37 KB
Del
OK
pkgng.py
685 B
Del
OK
pkgrepo.py
27.53 KB
Del
OK
portage_config.py
5.01 KB
Del
OK
ports.py
5.65 KB
Del
OK
postgres_cluster.py
4.19 KB
Del
OK
postgres_database.py
6.08 KB
Del
OK
postgres_extension.py
5.68 KB
Del
OK
postgres_group.py
8.52 KB
Del
OK
postgres_initdb.py
2.84 KB
Del
OK
postgres_language.py
3.94 KB
Del
OK
postgres_privileges.py
7.86 KB
Del
OK
postgres_schema.py
4.34 KB
Del
OK
postgres_tablespace.py
6.62 KB
Del
OK
postgres_user.py
9.49 KB
Del
OK
powerpath.py
2.34 KB
Del
OK
probes.py
15.06 KB
Del
OK
process.py
1.32 KB
Del
OK
proxy.py
4.94 KB
Del
OK
pushover.py
3.13 KB
Del
OK
pyenv.py
6.07 KB
Del
OK
pyrax_queues.py
2.97 KB
Del
OK
quota.py
1.4 KB
Del
OK
rabbitmq_cluster.py
1.84 KB
Del
OK
rabbitmq_plugin.py
2.77 KB
Del
OK
rabbitmq_policy.py
4.59 KB
Del
OK
rabbitmq_upstream.py
7.9 KB
Del
OK
rabbitmq_user.py
8.89 KB
Del
OK
rabbitmq_vhost.py
3.04 KB
Del
OK
rbac_solaris.py
6.67 KB
Del
OK
rbenv.py
7.36 KB
Del
OK
rdp.py
1.28 KB
Del
OK
redismod.py
4.76 KB
Del
OK
reg.py
19.22 KB
Del
OK
restconf.py
6.41 KB
Del
OK
rsync.py
4.45 KB
Del
OK
rvm.py
6.56 KB
Del
OK
salt_proxy.py
1.34 KB
Del
OK
saltmod.py
33.12 KB
Del
OK
saltutil.py
8.91 KB
Del
OK
schedule.py
12.47 KB
Del
OK
selinux.py
18.61 KB
Del
OK
serverdensity_device.py
6.41 KB
Del
OK
service.py
37.89 KB
Del
OK
slack.py
4.98 KB
Del
OK
smartos.py
44.83 KB
Del
OK
smtp.py
2.3 KB
Del
OK
snapper.py
7.24 KB
Del
OK
solrcloud.py
4.48 KB
Del
OK
splunk.py
4.32 KB
Del
OK
splunk_search.py
3.17 KB
Del
OK
sqlite3.py
14.7 KB
Del
OK
ssh_auth.py
19.57 KB
Del
OK
ssh_known_hosts.py
7.92 KB
Del
OK
stateconf.py
494 B
Del
OK
status.py
2.21 KB
Del
OK
statuspage.py
17.29 KB
Del
OK
supervisord.py
10.48 KB
Del
OK
svn.py
8.14 KB
Del
OK
sysctl.py
4.11 KB
Del
OK
sysfs.py
2.13 KB
Del
OK
syslog_ng.py
2.97 KB
Del
OK
sysrc.py
2.82 KB
Del
OK
telemetry_alert.py
7.04 KB
Del
OK
test.py
13.09 KB
Del
OK
testinframod.py
1.35 KB
Del
OK
timezone.py
3.42 KB
Del
OK
tls.py
1.81 KB
Del
OK
tomcat.py
9.72 KB
Del
OK
trafficserver.py
8.82 KB
Del
OK
tuned.py
3.32 KB
Del
OK
uptime.py
1.87 KB
Del
OK
user.py
38.63 KB
Del
OK
vagrant.py
11.4 KB
Del
OK
vault.py
3.28 KB
Del
OK
vbox_guest.py
4.05 KB
Del
OK
victorops.py
3.32 KB
Del
OK
virt.py
80.41 KB
Del
OK
virtualenv_mod.py
11.21 KB
Del
OK
webutil.py
3.89 KB
Del
OK
win_certutil.py
4.8 KB
Del
OK
win_dacl.py
7.96 KB
Del
OK
win_dism.py
14.97 KB
Del
OK
win_dns_client.py
8.32 KB
Del
OK
win_firewall.py
6.87 KB
Del
OK
win_iis.py
31.56 KB
Del
OK
win_lgpo.py
24.99 KB
Del
OK
win_lgpo_reg.py
10.96 KB
Del
OK
win_license.py
1.6 KB
Del
OK
win_network.py
14.18 KB
Del
OK
win_path.py
6.39 KB
Del
OK
win_pki.py
5.56 KB
Del
OK
win_powercfg.py
3.79 KB
Del
OK
win_servermanager.py
10.4 KB
Del
OK
win_shortcut.py
7.81 KB
Del
OK
win_smtp_server.py
10.01 KB
Del
OK
win_snmp.py
6.64 KB
Del
OK
win_system.py
13.78 KB
Del
OK
win_wua.py
16.27 KB
Del
OK
win_wusa.py
3.53 KB
Del
OK
winrepo.py
2.74 KB
Del
OK
wordpress.py
4.82 KB
Del
OK
x509.py
27.86 KB
Del
OK
x509_v2.py
64.78 KB
Del
OK
xml.py
1.75 KB
Del
OK
xmpp.py
2.61 KB
Del
OK
zabbix_action.py
9.35 KB
Del
OK
zabbix_host.py
27.25 KB
Del
OK
zabbix_hostgroup.py
5.64 KB
Del
OK
zabbix_mediatype.py
16.89 KB
Del
OK
zabbix_template.py
35.14 KB
Del
OK
zabbix_user.py
17.6 KB
Del
OK
zabbix_usergroup.py
9.64 KB
Del
OK
zabbix_usermacro.py
9.69 KB
Del
OK
zabbix_valuemap.py
8.11 KB
Del
OK
zcbuildout.py
5.16 KB
Del
OK
zenoss.py
2.89 KB
Del
OK
zfs.py
34.48 KB
Del
OK
zk_concurrency.py
5.81 KB
Del
OK
zone.py
46.48 KB
Del
OK
zookeeper.py
11.55 KB
Del
OK
zpool.py
13.4 KB
Del
OK
Edit: boto_lambda.py
""" Manage Lambda Functions ======================= .. versionadded:: 2016.3.0 Create and destroy Lambda Functions. Be aware that this interacts with Amazon's services, and so may incur charges. :depends: - boto - boto3 The dependencies listed above can be installed via package or pip. This module accepts explicit vpc credentials but can also utilize IAM roles assigned to the instance through Instance Profiles. Dynamic credentials are then automatically obtained from AWS API and no further configuration is necessary. More information available `here <http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html>`_. If IAM roles are not used you need to specify them either in a pillar file or in the minion's config file: .. code-block:: yaml vpc.keyid: GKTADJGHEIQSXMKKRBJ08H vpc.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs It's also possible to specify ``key``, ``keyid`` and ``region`` via a profile, either passed in as a dict, or as a string to pull from pillars or minion config: .. code-block:: yaml myprofile: keyid: GKTADJGHEIQSXMKKRBJ08H key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs region: us-east-1 .. code-block:: yaml Ensure function exists: boto_lambda.function_present: - FunctionName: myfunction - Runtime: python2.7 - Role: iam_role_name - Handler: entry_function - ZipFile: code.zip - S3Bucket: bucketname - S3Key: keyname - S3ObjectVersion: version - Description: "My Lambda Function" - Timeout: 3 - MemorySize: 128 - region: us-east-1 - keyid: GKTADJGHEIQSXMKKRBJ08H - key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs """ import hashlib import logging import os import salt.utils.data import salt.utils.dictupdate as dictupdate import salt.utils.files import salt.utils.json from salt.exceptions import SaltInvocationError log = logging.getLogger(__name__) def __virtual__(): """ Only load if boto is available. """ if "boto_lambda.function_exists" in __salt__: return "boto_lambda" return (False, "boto_lambda module could not be loaded") def function_present( name, FunctionName, Runtime, Role, Handler, ZipFile=None, S3Bucket=None, S3Key=None, S3ObjectVersion=None, Description="", Timeout=3, MemorySize=128, Permissions=None, RoleRetries=5, region=None, key=None, keyid=None, profile=None, VpcConfig=None, Environment=None, ): """ Ensure function exists. name The name of the state definition FunctionName Name of the Function. Runtime The Runtime environment for the function. One of 'nodejs', 'java8', or 'python2.7' Role The name or ARN of the IAM role that the function assumes when it executes your function to access any other AWS resources. Handler The function within your code that Lambda calls to begin execution. For Node.js it is the module-name.*export* value in your function. For Java, it can be package.classname::handler or package.class-name. ZipFile A path to a .zip file containing your deployment package. If this is specified, S3Bucket and S3Key must not be specified. S3Bucket Amazon S3 bucket name where the .zip file containing your package is stored. If this is specified, S3Key must be specified and ZipFile must NOT be specified. S3Key The Amazon S3 object (the deployment package) key name you want to upload. If this is specified, S3Key must be specified and ZipFile must NOT be specified. S3ObjectVersion The version of S3 object to use. Optional, should only be specified if S3Bucket and S3Key are specified. Description A short, user-defined function description. Lambda does not use this value. Assign a meaningful description as you see fit. Timeout The function execution time at which Lambda should terminate this function. Because the execution time has cost implications, we recommend you set this value based on your expected execution time. The default is 3 seconds. MemorySize The amount of memory, in MB, your function is given. Lambda uses this memory size to infer the amount of CPU and memory allocated to your function. Your function use-case determines your CPU and memory requirements. For example, a database operation might need less memory compared to an image processing function. The default value is 128 MB. The value must be a multiple of 64 MB. VpcConfig If your Lambda function accesses resources in a VPC, you must provide this parameter identifying the list of security group IDs/Names and subnet IDs/Name. These must all belong to the same VPC. This is a dict of the form: .. code-block:: yaml VpcConfig: SecurityGroupNames: - mysecgroup1 - mysecgroup2 SecurityGroupIds: - sg-abcdef1234 SubnetNames: - mysubnet1 SubnetIds: - subnet-1234abcd - subnet-abcd1234 If VpcConfig is provided at all, you MUST pass at least one security group and one subnet. Permissions A list of permission definitions to be added to the function's policy RoleRetries IAM Roles may take some time to propagate to all regions once created. During that time function creation may fail; this state will atuomatically retry this number of times. The default is 5. Environment The parent object that contains your environment's configuration settings. This is a dictionary of the form: .. code-block:: python { 'Variables': { 'VariableName': 'VariableValue' } } .. versionadded:: 2017.7.0 region Region to connect to. key Secret key to be used. keyid Access key to be used. profile A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid. """ ret = {"name": FunctionName, "result": True, "comment": "", "changes": {}} if Permissions is not None: if isinstance(Permissions, str): Permissions = salt.utils.json.loads(Permissions) required_keys = {"Action", "Principal"} optional_keys = {"SourceArn", "SourceAccount", "Qualifier"} for sid, permission in Permissions.items(): keyset = set(permission.keys()) if not keyset.issuperset(required_keys): raise SaltInvocationError( "{} are required for each permission specification".format( ", ".join(required_keys) ) ) keyset = keyset - required_keys keyset = keyset - optional_keys if bool(keyset): raise SaltInvocationError( "Invalid permission value {}".format(", ".join(keyset)) ) r = __salt__["boto_lambda.function_exists"]( FunctionName=FunctionName, region=region, key=key, keyid=keyid, profile=profile ) if "error" in r: ret["result"] = False ret["comment"] = "Failed to create function: {}.".format(r["error"]["message"]) return ret if not r.get("exists"): if __opts__["test"]: ret["comment"] = "Function {} is set to be created.".format(FunctionName) ret["result"] = None return ret r = __salt__["boto_lambda.create_function"]( FunctionName=FunctionName, Runtime=Runtime, Role=Role, Handler=Handler, ZipFile=ZipFile, S3Bucket=S3Bucket, S3Key=S3Key, S3ObjectVersion=S3ObjectVersion, Description=Description, Timeout=Timeout, MemorySize=MemorySize, VpcConfig=VpcConfig, Environment=Environment, WaitForRole=True, RoleRetries=RoleRetries, region=region, key=key, keyid=keyid, profile=profile, ) if not r.get("created"): ret["result"] = False ret["comment"] = "Failed to create function: {}.".format( r["error"]["message"] ) return ret if Permissions: for sid, permission in Permissions.items(): r = __salt__["boto_lambda.add_permission"]( FunctionName=FunctionName, StatementId=sid, region=region, key=key, keyid=keyid, profile=profile, **permission ) if not r.get("updated"): ret["result"] = False ret["comment"] = "Failed to create function: {}.".format( r["error"]["message"] ) _describe = __salt__["boto_lambda.describe_function"]( FunctionName, region=region, key=key, keyid=keyid, profile=profile ) _describe["function"]["Permissions"] = __salt__["boto_lambda.get_permissions"]( FunctionName, region=region, key=key, keyid=keyid, profile=profile )["permissions"] ret["changes"]["old"] = {"function": None} ret["changes"]["new"] = _describe ret["comment"] = "Function {} created.".format(FunctionName) return ret ret["comment"] = os.linesep.join( [ret["comment"], "Function {} is present.".format(FunctionName)] ) ret["changes"] = {} # function exists, ensure config matches _ret = _function_config_present( FunctionName, Role, Handler, Description, Timeout, MemorySize, VpcConfig, Environment, region, key, keyid, profile, RoleRetries, ) if not _ret.get("result"): ret["result"] = _ret.get("result", False) ret["comment"] = _ret["comment"] ret["changes"] = {} return ret ret["changes"] = dictupdate.update(ret["changes"], _ret["changes"]) ret["comment"] = " ".join([ret["comment"], _ret["comment"]]) _ret = _function_code_present( FunctionName, ZipFile, S3Bucket, S3Key, S3ObjectVersion, region, key, keyid, profile, ) if not _ret.get("result"): ret["result"] = _ret.get("result", False) ret["comment"] = _ret["comment"] ret["changes"] = {} return ret ret["changes"] = dictupdate.update(ret["changes"], _ret["changes"]) ret["comment"] = " ".join([ret["comment"], _ret["comment"]]) _ret = _function_permissions_present( FunctionName, Permissions, region, key, keyid, profile ) if not _ret.get("result"): ret["result"] = _ret.get("result", False) ret["comment"] = _ret["comment"] ret["changes"] = {} return ret ret["changes"] = dictupdate.update(ret["changes"], _ret["changes"]) ret["comment"] = " ".join([ret["comment"], _ret["comment"]]) return ret def _get_role_arn(name, region=None, key=None, keyid=None, profile=None): if name.startswith("arn:aws:iam:"): return name account_id = __salt__["boto_iam.get_account_id"]( region=region, key=key, keyid=keyid, profile=profile ) return "arn:aws:iam::{}:role/{}".format(account_id, name) def _resolve_vpcconfig(conf, region=None, key=None, keyid=None, profile=None): if isinstance(conf, str): conf = salt.utils.json.loads(conf) if not conf: # if the conf is None, we should explicitly set the VpcConfig to # {'SubnetIds': [], 'SecurityGroupIds': []} to take the lambda out of # the VPC it was in return {"SubnetIds": [], "SecurityGroupIds": []} if not isinstance(conf, dict): raise SaltInvocationError("VpcConfig must be a dict.") sns = [ __salt__["boto_vpc.get_resource_id"]( "subnet", s, region=region, key=key, keyid=keyid, profile=profile ).get("id") for s in conf.pop("SubnetNames", []) ] sgs = [ __salt__["boto_secgroup.get_group_id"]( s, region=region, key=key, keyid=keyid, profile=profile ) for s in conf.pop("SecurityGroupNames", []) ] conf.setdefault("SubnetIds", []).extend(sns) conf.setdefault("SecurityGroupIds", []).extend(sgs) return conf def _function_config_present( FunctionName, Role, Handler, Description, Timeout, MemorySize, VpcConfig, Environment, region, key, keyid, profile, RoleRetries, ): ret = {"result": True, "comment": "", "changes": {}} func = __salt__["boto_lambda.describe_function"]( FunctionName, region=region, key=key, keyid=keyid, profile=profile )["function"] need_update = False options = { "Role": _get_role_arn(Role, region, key, keyid, profile), "Handler": Handler, "Description": Description, "Timeout": Timeout, "MemorySize": MemorySize, } for key, val in options.items(): if func[key] != val: need_update = True ret["changes"].setdefault("old", {})[key] = func[key] ret["changes"].setdefault("new", {})[key] = val # VpcConfig returns the extra value 'VpcId' so do a special compare oldval = func.get("VpcConfig") if oldval is not None: oldval.pop("VpcId", None) fixed_VpcConfig = _resolve_vpcconfig(VpcConfig, region, key, keyid, profile) if __utils__["boto3.ordered"](oldval) != __utils__["boto3.ordered"]( fixed_VpcConfig ): need_update = True ret["changes"].setdefault("new", {})["VpcConfig"] = fixed_VpcConfig ret["changes"].setdefault("old", {})["VpcConfig"] = func.get("VpcConfig") if Environment is not None: if func.get("Environment") != Environment: need_update = True ret["changes"].setdefault("new", {})["Environment"] = Environment ret["changes"].setdefault("old", {})["Environment"] = func.get( "Environment" ) if need_update: ret["comment"] = os.linesep.join( [ret["comment"], "Function config to be modified"] ) if __opts__["test"]: ret["comment"] = "Function {} set to be modified.".format(FunctionName) ret["result"] = None return ret _r = __salt__["boto_lambda.update_function_config"]( FunctionName=FunctionName, Role=Role, Handler=Handler, Description=Description, Timeout=Timeout, MemorySize=MemorySize, VpcConfig=fixed_VpcConfig, Environment=Environment, region=region, key=key, keyid=keyid, profile=profile, WaitForRole=True, RoleRetries=RoleRetries, ) if not _r.get("updated"): ret["result"] = False ret["comment"] = "Failed to update function: {}.".format( _r["error"]["message"] ) ret["changes"] = {} return ret def _function_code_present( FunctionName, ZipFile, S3Bucket, S3Key, S3ObjectVersion, region, key, keyid, profile ): ret = {"result": True, "comment": "", "changes": {}} func = __salt__["boto_lambda.describe_function"]( FunctionName, region=region, key=key, keyid=keyid, profile=profile )["function"] update = False if ZipFile: if "://" in ZipFile: # Looks like a remote URL to me... dlZipFile = __salt__["cp.cache_file"](path=ZipFile) if dlZipFile is False: ret["result"] = False ret["comment"] = "Failed to cache ZipFile `{}`.".format(ZipFile) return ret ZipFile = dlZipFile size = os.path.getsize(ZipFile) if size == func["CodeSize"]: sha = hashlib.sha256() with salt.utils.files.fopen(ZipFile, "rb") as f: sha.update(f.read()) hashed = sha.digest().encode("base64").strip() if hashed != func["CodeSha256"]: update = True else: update = True else: # No way to judge whether the item in the s3 bucket is current without # downloading it. Cheaper to just request an update every time, and still # idempotent update = True if update: if __opts__["test"]: ret["comment"] = "Function {} set to be modified.".format(FunctionName) ret["result"] = None return ret ret["changes"]["old"] = { "CodeSha256": func["CodeSha256"], "CodeSize": func["CodeSize"], } func = __salt__["boto_lambda.update_function_code"]( FunctionName, ZipFile, S3Bucket, S3Key, S3ObjectVersion, region=region, key=key, keyid=keyid, profile=profile, ) if not func.get("updated"): ret["result"] = False ret["comment"] = "Failed to update function: {}.".format( func["error"]["message"] ) ret["changes"] = {} return ret func = func["function"] if ( func["CodeSha256"] != ret["changes"]["old"]["CodeSha256"] or func["CodeSize"] != ret["changes"]["old"]["CodeSize"] ): ret["comment"] = os.linesep.join( [ret["comment"], "Function code to be modified"] ) ret["changes"]["new"] = { "CodeSha256": func["CodeSha256"], "CodeSize": func["CodeSize"], } else: del ret["changes"]["old"] return ret def _function_permissions_present( FunctionName, Permissions, region, key, keyid, profile ): ret = {"result": True, "comment": "", "changes": {}} curr_permissions = __salt__["boto_lambda.get_permissions"]( FunctionName, region=region, key=key, keyid=keyid, profile=profile ).get("permissions") if curr_permissions is None: curr_permissions = {} need_update = False diffs = salt.utils.data.compare_dicts(curr_permissions, Permissions or {}) if bool(diffs): ret["comment"] = os.linesep.join( [ret["comment"], "Function permissions to be modified"] ) if __opts__["test"]: ret["comment"] = "Function {} set to be modified.".format(FunctionName) ret["result"] = None return ret for sid, diff in diffs.items(): if diff.get("old", "") != "": # There's a permssion that needs to be removed _r = __salt__["boto_lambda.remove_permission"]( FunctionName=FunctionName, StatementId=sid, region=region, key=key, keyid=keyid, profile=profile, ) ret["changes"].setdefault("new", {}).setdefault("Permissions", {})[ sid ] = {} ret["changes"].setdefault("old", {}).setdefault("Permissions", {})[ sid ] = diff["old"] if diff.get("new", "") != "": # New permission information needs to be added _r = __salt__["boto_lambda.add_permission"]( FunctionName=FunctionName, StatementId=sid, region=region, key=key, keyid=keyid, profile=profile, **diff["new"] ) ret["changes"].setdefault("new", {}).setdefault("Permissions", {})[ sid ] = diff["new"] oldperms = ( ret["changes"].setdefault("old", {}).setdefault("Permissions", {}) ) if sid not in oldperms: oldperms[sid] = {} if not _r.get("updated"): ret["result"] = False ret["comment"] = "Failed to update function: {}.".format( _r["error"]["message"] ) ret["changes"] = {} return ret def function_absent( name, FunctionName, region=None, key=None, keyid=None, profile=None ): """ Ensure function with passed properties is absent. name The name of the state definition. FunctionName Name of the function. region Region to connect to. key Secret key to be used. keyid Access key to be used. profile A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid. """ ret = {"name": FunctionName, "result": True, "comment": "", "changes": {}} r = __salt__["boto_lambda.function_exists"]( FunctionName, region=region, key=key, keyid=keyid, profile=profile ) if "error" in r: ret["result"] = False ret["comment"] = "Failed to delete function: {}.".format(r["error"]["message"]) return ret if r and not r["exists"]: ret["comment"] = "Function {} does not exist.".format(FunctionName) return ret if __opts__["test"]: ret["comment"] = "Function {} is set to be removed.".format(FunctionName) ret["result"] = None return ret r = __salt__["boto_lambda.delete_function"]( FunctionName, region=region, key=key, keyid=keyid, profile=profile ) if not r["deleted"]: ret["result"] = False ret["comment"] = "Failed to delete function: {}.".format(r["error"]["message"]) return ret ret["changes"]["old"] = {"function": FunctionName} ret["changes"]["new"] = {"function": None} ret["comment"] = "Function {} deleted.".format(FunctionName) return ret def alias_present( name, FunctionName, Name, FunctionVersion, Description="", region=None, key=None, keyid=None, profile=None, ): """ Ensure alias exists. name The name of the state definition. FunctionName Name of the function for which you want to create an alias. Name The name of the alias to be created. FunctionVersion Function version for which you are creating the alias. Description A short, user-defined function description. Lambda does not use this value. Assign a meaningful description as you see fit. region Region to connect to. key Secret key to be used. keyid Access key to be used. profile A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid. """ ret = {"name": Name, "result": True, "comment": "", "changes": {}} r = __salt__["boto_lambda.alias_exists"]( FunctionName=FunctionName, Name=Name, region=region, key=key, keyid=keyid, profile=profile, ) if "error" in r: ret["result"] = False ret["comment"] = "Failed to create alias: {}.".format(r["error"]["message"]) return ret if not r.get("exists"): if __opts__["test"]: ret["comment"] = "Alias {} is set to be created.".format(Name) ret["result"] = None return ret r = __salt__["boto_lambda.create_alias"]( FunctionName, Name, FunctionVersion, Description, region, key, keyid, profile, ) if not r.get("created"): ret["result"] = False ret["comment"] = "Failed to create alias: {}.".format(r["error"]["message"]) return ret _describe = __salt__["boto_lambda.describe_alias"]( FunctionName, Name, region=region, key=key, keyid=keyid, profile=profile ) ret["changes"]["old"] = {"alias": None} ret["changes"]["new"] = _describe ret["comment"] = "Alias {} created.".format(Name) return ret ret["comment"] = os.linesep.join( [ret["comment"], "Alias {} is present.".format(Name)] ) ret["changes"] = {} _describe = __salt__["boto_lambda.describe_alias"]( FunctionName, Name, region=region, key=key, keyid=keyid, profile=profile )["alias"] need_update = False options = {"FunctionVersion": FunctionVersion, "Description": Description} for key, val in options.items(): if _describe[key] != val: need_update = True ret["changes"].setdefault("old", {})[key] = _describe[key] ret["changes"].setdefault("new", {})[key] = val if need_update: ret["comment"] = os.linesep.join( [ret["comment"], "Alias config to be modified"] ) if __opts__["test"]: ret["comment"] = "Alias {} set to be modified.".format(Name) ret["result"] = None return ret _r = __salt__["boto_lambda.update_alias"]( FunctionName=FunctionName, Name=Name, FunctionVersion=FunctionVersion, Description=Description, region=region, key=key, keyid=keyid, profile=profile, ) if not _r.get("updated"): ret["result"] = False ret["comment"] = "Failed to update alias: {}.".format( _r["error"]["message"] ) ret["changes"] = {} return ret def alias_absent( name, FunctionName, Name, region=None, key=None, keyid=None, profile=None ): """ Ensure alias with passed properties is absent. name The name of the state definition. FunctionName Name of the function. Name Name of the alias. region Region to connect to. key Secret key to be used. keyid Access key to be used. profile A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid. """ ret = {"name": Name, "result": True, "comment": "", "changes": {}} r = __salt__["boto_lambda.alias_exists"]( FunctionName, Name, region=region, key=key, keyid=keyid, profile=profile ) if "error" in r: ret["result"] = False ret["comment"] = "Failed to delete alias: {}.".format(r["error"]["message"]) return ret if r and not r["exists"]: ret["comment"] = "Alias {} does not exist.".format(Name) return ret if __opts__["test"]: ret["comment"] = "Alias {} is set to be removed.".format(Name) ret["result"] = None return ret r = __salt__["boto_lambda.delete_alias"]( FunctionName, Name, region=region, key=key, keyid=keyid, profile=profile ) if not r["deleted"]: ret["result"] = False ret["comment"] = "Failed to delete alias: {}.".format(r["error"]["message"]) return ret ret["changes"]["old"] = {"alias": Name} ret["changes"]["new"] = {"alias": None} ret["comment"] = "Alias {} deleted.".format(Name) return ret def _get_function_arn(name, region=None, key=None, keyid=None, profile=None): if name.startswith("arn:aws:lambda:"): return name account_id = __salt__["boto_iam.get_account_id"]( region=region, key=key, keyid=keyid, profile=profile ) if profile and "region" in profile: region = profile["region"] if region is None: region = "us-east-1" return "arn:aws:lambda:{}:{}:function:{}".format(region, account_id, name) def event_source_mapping_present( name, EventSourceArn, FunctionName, StartingPosition, Enabled=True, BatchSize=100, region=None, key=None, keyid=None, profile=None, ): """ Ensure event source mapping exists. name The name of the state definition. EventSourceArn The Amazon Resource Name (ARN) of the Amazon Kinesis or the Amazon DynamoDB stream that is the event source. FunctionName The Lambda function to invoke when AWS Lambda detects an event on the stream. You can specify an unqualified function name (for example, "Thumbnail") or you can specify Amazon Resource Name (ARN) of the function (for example, "arn:aws:lambda:us-west-2:account-id:function:ThumbNail"). AWS Lambda also allows you to specify only the account ID qualifier (for example, "account-id:Thumbnail"). Note that the length constraint applies only to the ARN. If you specify only the function name, it is limited to 64 character in length. StartingPosition The position in the stream where AWS Lambda should start reading. (TRIM_HORIZON | LATEST) Enabled Indicates whether AWS Lambda should begin polling the event source. By default, Enabled is true. BatchSize The largest number of records that AWS Lambda will retrieve from your event source at the time of invoking your function. Your function receives an event with all the retrieved records. The default is 100 records. region Region to connect to. key Secret key to be used. keyid Access key to be used. profile A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid. """ ret = {"name": None, "result": True, "comment": "", "changes": {}} r = __salt__["boto_lambda.event_source_mapping_exists"]( EventSourceArn=EventSourceArn, FunctionName=FunctionName, region=region, key=key, keyid=keyid, profile=profile, ) if "error" in r: ret["result"] = False ret["comment"] = "Failed to create event source mapping: {}.".format( r["error"]["message"] ) return ret if not r.get("exists"): if __opts__["test"]: ret["comment"] = "Event source mapping {} is set to be created.".format( FunctionName ) ret["result"] = None return ret r = __salt__["boto_lambda.create_event_source_mapping"]( EventSourceArn=EventSourceArn, FunctionName=FunctionName, StartingPosition=StartingPosition, Enabled=Enabled, BatchSize=BatchSize, region=region, key=key, keyid=keyid, profile=profile, ) if not r.get("created"): ret["result"] = False ret["comment"] = "Failed to create event source mapping: {}.".format( r["error"]["message"] ) return ret _describe = __salt__["boto_lambda.describe_event_source_mapping"]( EventSourceArn=EventSourceArn, FunctionName=FunctionName, region=region, key=key, keyid=keyid, profile=profile, ) ret["name"] = _describe["event_source_mapping"]["UUID"] ret["changes"]["old"] = {"event_source_mapping": None} ret["changes"]["new"] = _describe ret["comment"] = "Event source mapping {} created.".format(ret["name"]) return ret ret["comment"] = os.linesep.join( [ret["comment"], "Event source mapping is present."] ) ret["changes"] = {} _describe = __salt__["boto_lambda.describe_event_source_mapping"]( EventSourceArn=EventSourceArn, FunctionName=FunctionName, region=region, key=key, keyid=keyid, profile=profile, )["event_source_mapping"] need_update = False options = {"BatchSize": BatchSize} for key, val in options.items(): if _describe[key] != val: need_update = True ret["changes"].setdefault("old", {})[key] = _describe[key] ret["changes"].setdefault("new", {})[key] = val # verify FunctionName against FunctionArn function_arn = _get_function_arn( FunctionName, region=region, key=key, keyid=keyid, profile=profile ) if _describe["FunctionArn"] != function_arn: need_update = True ret["changes"].setdefault("new", {})["FunctionArn"] = function_arn ret["changes"].setdefault("old", {})["FunctionArn"] = _describe["FunctionArn"] # TODO check for 'Enabled', since it doesn't directly map to a specific # state if need_update: ret["comment"] = os.linesep.join( [ret["comment"], "Event source mapping to be modified"] ) if __opts__["test"]: ret["comment"] = "Event source mapping {} set to be modified.".format( _describe["UUID"] ) ret["result"] = None return ret _r = __salt__["boto_lambda.update_event_source_mapping"]( UUID=_describe["UUID"], FunctionName=FunctionName, Enabled=Enabled, BatchSize=BatchSize, region=region, key=key, keyid=keyid, profile=profile, ) if not _r.get("updated"): ret["result"] = False ret["comment"] = "Failed to update mapping: {}.".format( _r["error"]["message"] ) ret["changes"] = {} return ret def event_source_mapping_absent( name, EventSourceArn, FunctionName, region=None, key=None, keyid=None, profile=None ): """ Ensure event source mapping with passed properties is absent. name The name of the state definition. EventSourceArn ARN of the event source. FunctionName Name of the lambda function. region Region to connect to. key Secret key to be used. keyid Access key to be used. profile A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid. """ ret = {"name": None, "result": True, "comment": "", "changes": {}} desc = __salt__["boto_lambda.describe_event_source_mapping"]( EventSourceArn=EventSourceArn, FunctionName=FunctionName, region=region, key=key, keyid=keyid, profile=profile, ) if "error" in desc: ret["result"] = False ret["comment"] = "Failed to delete event source mapping: {}.".format( desc["error"]["message"] ) return ret if not desc.get("event_source_mapping"): ret["comment"] = "Event source mapping does not exist." return ret ret["name"] = desc["event_source_mapping"]["UUID"] if __opts__["test"]: ret["comment"] = "Event source mapping is set to be removed." ret["result"] = None return ret r = __salt__["boto_lambda.delete_event_source_mapping"]( EventSourceArn=EventSourceArn, FunctionName=FunctionName, region=region, key=key, keyid=keyid, profile=profile, ) if not r["deleted"]: ret["result"] = False ret["comment"] = "Failed to delete event source mapping: {}.".format( r["error"]["message"] ) return ret ret["changes"]["old"] = desc ret["changes"]["new"] = {"event_source_mapping": None} ret["comment"] = "Event source mapping deleted." return ret
Save